Reputation: 145
php:
$sql = "SELECT id, menuname
FROM table
WHERE status = 'active'
ORDER BY order ASC";
$result = mysql_query($sql);
$menu = "<ul>\n";
while ($row = mysql_fetch_assoc($result)) {
$menu.= "<li><a href=\"?id={$row['id']}\">{$row['menuname']}</a></li>";
}
$menu.= "</ul>\n";
html:
<nav>
<ul>
<li><a href="?id=1">About</a></li>
<li><a href="?id=2">News</a></li>
<li><a href="?id=3">Prices</a></li>
<li><a href="?id=4">Gallery</a></li>
<li><a href="?id=5">Contact</a></li>
</ul>
</nav>
I'd like to add the class="lhidden" to the "News" (not the 2nd menu,because the order can be changed).
<li class="lhidden"><a href="?id=2">News</a></li>
How can i do that? I'm just learning javascript and php,so I have no idea :S
Upvotes: 0
Views: 124
Reputation: 29
$sql = "SELECT id, menuname
FROM table
WHERE status = 'active'
ORDER BY order ASC";
$result = mysql_query($sql);
$menu = "<ul>\n";
while ($row = mysql_fetch_assoc($result)) {
if($row['id']==2)
{
$menu.= "<li class=\"lhidden\"><a href=\"?id={$row['id']}\">{$row['menuname']}</a></li>";
}
else
{
$menu.= "<li><a href=\"?id={$row['id']}\">{$row['menuname']}</a></li>";
}
$menu.= "</ul>\n";
Upvotes: 0
Reputation: 97717
How about
while ($row = mysql_fetch_assoc($result)) {
$menu.= "<li><a".($row['menuname']=='News'?' class="lhidden"':'')." href=\"?id={$row['id']}\">{$row['menuname']}</a></li>";
}
Upvotes: 2
Reputation: 7491
Using jQuery is pretty easy:
$('a[href="?id=2"]').parent().addClass('lhidden');
This would first find the specific anchor, then add your class to its parent.
Documentation for the selector part here: http://api.jquery.com/attribute-equals-selector/
Upvotes: 0