Page 1 of 1

Sql not returning all results

Posted: Fri Oct 23, 2009 7:29 pm
by ardan16
Hi all,
Can some one please tell me why the following code would not return all results.

Code: Select all

<form action='#' method='post' id="search">
Search For An Incident By Date:
 
<select name="find"> 
<?php
require_once ('mysql_connect.php'); // Connect to the db.
$sql = "SELECT idate FROM report ORDER BY `idate` DESC";
$query = mysql_query($sql);
 
$data = mysql_fetch_array($query);
 
while($data = mysql_fetch_array($query)){
         echo "<option value=\"" . $data ['idate'] . "\">" . $data ['idate'] . "</option>";
}
        
?>
 
</select>
    <input type="submit" name="submit" value="Search">
   <input type="hidden" name="submitted" value="TRUE" />
    </form>
ie the the column has x results it is returning x-1 all the time.
Please Help
Been looking at it way too long.

Re: Sql not returning all results

Posted: Fri Oct 23, 2009 7:53 pm
by requinix

Code: Select all

$data = mysql_fetch_array($query);
 
while($data = mysql_fetch_array($query)){
So what happened to the first $data? Where'd it go? What did you do with it?

Spoiler: you lost it. That's where the missing row is. Just get rid of that line.

Re: Sql not returning all results

Posted: Fri Oct 23, 2009 8:03 pm
by ardan16
Thanks tasairis,
Like I said, I spent way too long looking at it.