Jump to content

Looping problem


gerkintrigg

Recommended Posts

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:

[code]<?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>';
                        }
                        ?>[/code]

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.
Link to comment
https://forums.phpfreaks.com/topic/8048-looping-problem/
Share on other sites

You're retrieiving the first record, doing nothing with it and then retrieving the rest. Remove the first msql_fetch...
[code]<?php
$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>';
?>[/code]

Ken
Link to comment
https://forums.phpfreaks.com/topic/8048-looping-problem/#findComment-29382
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.