Forum Moderators: coopster

Message Too Old, No Replies

Dynamic navigation menu

determine the current page and echo w/out <a>

         

Birdman

5:24 pm on Nov 20, 2002 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Hi all,

I'm creating my navigation menu dynamically so they will be easy to update site wide at a later date.

So, I've got it working using the function below, however I want to be able to determine the current page and remove the anchor tags from that entry on the menu.

I figured out how to get the file name of the current page into a variable(Which will match $link[nav_href]). How should I proceed from here? I think I need an if/else statement but can't get it:(


function left_nav(){
$query = "SELECT * FROM cats WHERE cat_side = 'left'";
$cats = mysql_query($query);

while($cat = mysql_fetch_array($cats)) {
echo "<h2>$cat[cat_name]</h2><div class='nav'>";
$query2 = "SELECT * FROM nav Where nav_cat_id = $cat[cat_id]";
$sql = mysql_query($query2);

while($link = mysql_fetch_array($sql)) {
echo "<p><a href='$link[nav_href]'>
<img src='my_img.gif' /> $link[nav_name]</a></p>";

}
echo "</div>";
}
}

andreasfriedrich

5:49 pm on Nov 20, 2002 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



while($link = mysql_fetch_array($sql)) {  
if ($link['nav_href'] <> $current_page) {
echo <<<END
<p><a href="$link[nav_href]">
<img src="my_img.gif" /> $link[nav_name]</a></p>
END;
} else {
echo "<p>$link[nav_name]</p>";
}
}

should work.

Andreas

Birdman

3:30 pm on Nov 21, 2002 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Thanks andreas!
I can't wait 'till I can whip up code as easy as you and others around here. Appreciate the help, again.

Could you or someone else explain the <<<END END;

andreasfriedrich

3:36 pm on Nov 21, 2002 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Thatīs PHPīs heredoc syntax [php.net]. Everything between <<<END_MARKER and END_MARKER; is treated as a double quoted string. Using it here avoids to escape the double quotes that get used to delimit the html attributes. You used single quotes for that, but XHTML requires double quotes.

Andreas

Birdman

3:42 pm on Nov 21, 2002 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Interesting? I did not know XHTML required double quotes. I guess it's the dreaded validation time, to see what other mistakes I have in there.

I was starting to get in the habit of using single quotes just so it wouldn't bother the php.

andreasfriedrich

4:12 pm on Nov 21, 2002 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Sorry Birdman, I think I got that one wrong.

The XML spec defines [w3.org]:

AttValue ::= '"' ([^<&"] Ķ Reference)* '"'  
Ķ "'" ([^<&'] Ķ Reference)* "'"

So I guess that means both single and double quotes are ok. I couldnīt find anything in the XHTML spec that is more restrictive.

I believe itīs SGML that allows only double quotes.

Andreas