Jump to content


Looping problem

  • Please log in to reply
2 replies to this topic

#1 gerkintrigg

  • Members
  • PipPipPip
  • Magician
  • 828 posts
  • LocationBristol, UK
  • Age:37

Posted 21 April 2006 - 03:18 PM

Hi all.
I'm trying to loop through an SQL array (something I've done numerous times before) but this time it's retrieving all but one of the results...
here's the code I'm using:

<?php $sql = mysql_query("SELECT * FROM scenes LIMIT 9999");
                      $p = mysql_fetch_array($sql);?>
                      <select name="select" class="search">
                      <?php while ($p = mysql_fetch_array($sql)){ 
                      echo '<option value="'.$p['scene_number'].'">Scene '.$p['scene_number'].' - Containing '.$p['no_of_shots'].' Shots</option>';

It's for a database of shots and can be found at [a href=\"http://www.magic2k.com/422/search/\" target=\"_blank\"]My development page[/a]

I've been staring at it for too long perhaps.

If anyone can help or suggest anything that could sort the problem that'd be great. Many thanks.
Neil Trigger - http://www.ghostlypublishing.co.uk - Ghostly Publishing - Children's Fantasy Books

#2 wisewood

  • Members
  • PipPipPip
  • Advanced Member
  • 226 posts
  • LocationRotherham, England

Posted 21 April 2006 - 03:26 PM

Started reading the code, first thing i thought of as i read it... Are there 10000 entries in the table?

wisewood: proven fact, I am both wise, and wooden.

#3 kenrbnsn

  • Staff Alumni
  • Advanced Member
  • 8,235 posts
  • LocationHillsborough, NJ, USA

Posted 21 April 2006 - 05:17 PM

You're retrieiving the first record, doing nothing with it and then retrieving the rest. Remove the first msql_fetch...
$sql = mysql_query("SELECT * FROM scenes LIMIT 9999");
echo '<select name="select" class="search">';
while ($p = mysql_fetch_array($sql))
        echo '<option value="'.$p['scene_number'].'">Scene '.$p['scene_number'].' - Containing '.$p['no_of_shots'].' Shots</option>';


0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users