Jump to content

Archived

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

gerkintrigg

Looping problem

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.

Share this post


Link to post
Share on other sites
Started reading the code, first thing i thought of as i read it... Are there 10000 entries in the table?

Share this post


Link to post
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

Share this post


Link to post
Share on other sites

×

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.