Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

SQL query not displaying the first result?

I am trying to dynamically create a navigation menu in my php page.

I have a query to create a list of the active pages but for some reason the first result never shows

$menu = mysql_query("SELECT link FROM myTable WHERE active_page='y' ORDER BY menu_order");
$menulist = mysql_fetch_array($menu);

  while($menulist = mysql_fetch_array($menu))
  {
  $themenu = $themenu . "<li><a href='#'>" . $menulist['link'] . "</a></li>";
  }

  $echo $themenu;

returns

item 2
item 3
item 4
...

Any ideas why this might be

like image 592
Tom Avatar asked Dec 01 '25 01:12

Tom


1 Answers

Remove

$menulist = mysql_fetch_array($menu);

This extraneous call is pulling the first record, but you're not doing anything with it as you are in your where loop.

like image 91
user470714 Avatar answered Dec 02 '25 14:12

user470714



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!