mysql - PHP first active button -


i have little question you!

i make selection mysql buttons example:

$query = mysql_query("select * navigation");  while ($row = mysql_fetch_assoc($query)) {      echo '<a href="?id=$row['id']">$row['name']</a>';  } 

so call navigation mysql , have class in css called .active, class make active button when click it, how can make first button active?

$query = mysql_query("select * navigation");  while ($row = mysql_fetch_assoc($query)) {       if ($row['id'] == $_get['id'])) {          echo '<a class="active" href="?id=$row['id']">$row['name']</a>';      } else {          echo '<a href="?id=$row['id']">$row['name']</a>';      }  } 

try this.

<?php $query = mysql_query("select * navigation"); $first = true; while($row = mysql_fetch_assoc($query)) {     if ((!array_key_exists('id', $_get) && $first) || $row['id'] == $_get['id']) {          $extra = 'class="active"';          $first = false;     } else          $extra = '';      echo "<a $extra href=\"?id={$row['id']}\">{$row['name']}</a>"; } ?> 

Comments

Popular posts from this blog

c# - SharpSVN - How to get the previous revision? -

c++ - Is it possible to compile a VST on linux? -

url - Querystring manipulation of email Address in PHP -