Forum Moderators: coopster

Message Too Old, No Replies

first attempt at php, first problem

php navigation menu help

         

huds

5:59 pm on Jun 8, 2005 (gmt 0)

10+ Year Member



Hello,

I've been banging my head off the wall trying to solve this problem for 3 days now.

I'm trying to create a navigation menu system, using two arrays (different columns within one mysql table) to represent each link and the corresponding link text.
I was hoping it would iterate through both columns, but it only seems to loop correctly on the second while statement.

here's the code...

// Print menu
echo "<table>\n";

while ($linkline = mysql_fetch_array($menulinks, MYSQL_ASSOC))
while ($textline = mysql_fetch_array($menutext, MYSQL_ASSOC))
foreach ($linkline as $links_menu) {
foreach ($textline as $links_text)
echo "\t\t<td class=$xostyle><a href=$links_menu>$links_text</a></td>\n";
echo "\t</tr>\n";
}

Any suggestions are appreciated, thank you.

Timotheos

6:11 pm on Jun 8, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Hi huds and welcome to WebmasterWorld,

Lets back up here. You only need one sql query. It should look something line "SELECT menu, text FROM yourtablename". Once you got that you just need one loop.

while ($row = mysql_fetch_assoc($result)) {

$links_menu = $row['menu'];
$links_text = $row['text'];

echo "\t\t<td class=$xostyle><a href=$links_menu>$links_text</a></td>\n";
echo "\t</tr>\n";

}

Something like that.
Tim

huds

7:21 pm on Jun 8, 2005 (gmt 0)

10+ Year Member



Thanks Tim,

That's a great help.

Now I can create my menu and start struggling with the next part :)