close ad
Databridge V2 with MySQLi support IS Now Available!
open ad
View Menu

Technical Support Forums

Free, outstanding support from WebAssist and your colleagues

rating

Alternating a menu system...

Thread began 10/10/2012 8:32 pm by Christopher West | Last modified 10/11/2012 3:06 pm by Christopher West | 595 views | 6 replies |

Christopher WestCommunity Expert

Alternating a menu system...

Hi there I am trying to alternate some HTML code (together with some PHP that will allow dynamic menu names and menu icons (so that I have a icon above the first menu name, then icon below the menu name...so on and so forth..

I found that I needed to use a PHP modulator to create this: The below example code shows the menu working how I want it (but in this example its just static menu items) But need for the menu items to be replaced with dynamic ones from the record set. Could you help to insert the dynamic code replacing the static menu items below (<p>Home</p> AND <p>Domestic</p> I have been experiementing with different approaches but nothing works as of yet :(

I did try the below code without any HTML in the echo and just simple echo'd the dymanic code from my record set..however it only displayed the first record so it wasnt going through the whole recordset...then I stupidly messed around with the code putting in a repeat region around the below code and changed some of the references then I got the recordset working however it was echo'ing duplicates (eg HOME HOME DOMESTIC DOMESTIC). So not sure why that way :-/

---------------------------------------------------------------------------
<?php
for($i = 0; $i < $totalRows_rsTopMenu; $i++)
{
$row = mysql_fetch_array($rsTopMenu);

if($i % 2) {
echo '<div class="nav"><p>Home</p><p><img src="../images/hand.jpg" width="38" height="44"></p></div>';
} else {
echo '<div class="nav"><p><img src="../images/hand.jpg" width="38" height="44"></p><p>Domestic</p></div>'; }
}
?>
---------------------------------------------------------------------------

my recordset is:

mysql_select_db($database_rainbowdb, $rainbowdb);
$query_rsTopMenu = "SELECT * FROM topmenu";
$rsTopMenu = mysql_query($query_rsTopMenu, $rainbowdb) or die(mysql_error());
$row_rsTopMenu = mysql_fetch_assoc($rsTopMenu);
$totalRows_rsTopMenu = mysql_num_rows($rsTopMenu);

---------------------------------------------------------------------------


Regards

Chris

Sign in to reply to this post

Jason ByrnesWebAssist

using a for loop like that is not the right way to do this. Use a repeat region, before the repeat region code, initialize $i = 0, do the modulus comparison inside the repeat region, and increment $i as the last instruction of the repeat:

php:
<?php $i 0// initialize $i ?>

<?php 
do { // start repeat ?>
<?php 
    
if($i 2) { // Modulus comparison
        
echo("Home<br />");
    } else { 
        echo(
"Domestic<br />");
    } 
    
$i++;  // increment $i
?>
<?php 
} while ($row_rsTopMenu mysql_fetch_assoc($rsTopMenu)); // end repeat?>
Sign in to reply to this post

Christopher WestCommunity Expert

That makes sense :) ...but in the echo I want to put this code in.....

echo('<div class="nav"><p style="margin-bottom:15px"><img src="../images/hand.jpg" width="38" height="44"></p><p>Domestic</p></div>');

....and where you see Domestic I want to replace with this....

<?php echo $row_rsTopMenu['TopMenuName']; ?>

So that any menu items stored in the database are displayed (rather then static content) But how can i put this into the echo (where Domestic is as its not allowing me to :(

Chris

Well I did some experimenting and got it to work in reverse:

echo('<div class="nav"><p style="margin-bottom:15px">'.$row_rsTopMenu['TopMenuName'].'</p><p><img src="../images/hand.jpg" width="38" height="44"></p></div>');

But just wondered why my database is displaying sequencually from right to left rather then from left to right

Sign in to reply to this post

Jason ByrnesWebAssist

use:

php:
echo('<div class="nav"><p style="margin-bottom:15px"><img  src="../images/hand.jpg" width="38" height="44"></p><p>'.$row_rsTopMenu['TopMenuName'].'</p></div>');
Sign in to reply to this post

Christopher WestCommunity Expert

isnt that the same code that I put in after I edited my reply ;-)

My follow up question though is that I had to ORDER bt DESC to get the menu items in correct order since they were displaying from right to left. Which I did find a little odd because if I were to write the code manually without using dynamic data I wouldnt need to write the code in reverse (if you know what Im getting at) :)

Just wondered why I needed to do ORDER by DESC rather then leave it as default.

Chris

Sign in to reply to this post

Jason ByrnesWebAssist

your edit that contained that code was made a minute after i posted.


the order by clause is setting the order of the results, the default is to use ascending, sounds like you want to use descending, so need to add the order by clause.

Sign in to reply to this post

Christopher WestCommunity Expert

Thanks Jason :)

Sign in to reply to this post

Build websites with a little help from your friends

Your friends over here at WebAssist! These Dreamweaver extensions will assist you in building unlimited, custom websites.

Build websites from already-built web applications

These out-of-the-box solutions provide you proven, tested applications that can be up and running now.  Build a store, a gallery, or a web-based email solution.

Want your website pre-built and hosted?

Close Windowclose

Rate your experience or provide feedback on this page

Account or customer service questions?
Please user our contact form.

Need technical support?
Please visit support to ask a question

Content

rating

Layout

rating

Ease of use

rating

security code refresh image

We do not respond to comments submitted from this page directly, but we do read and analyze any feedback and will use it to help make your experience better in the future.

Close Windowclose

We were unable to retrieve the attached file

Close Windowclose

Attach and remove files

add attachmentAdd attachment
Close Windowclose

Enter the URL you would like to link to in your post

Close Windowclose

This is how you use right click RTF editing

Enable right click RTF editing option allows you to add html markup into your tutorial such as images, bulleted lists, files and more...

-- click to close --

Uploading file...