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
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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.