PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!
Moderator: General Moderators
ardan16
Forum Commoner
Posts: 32 Joined: Fri Aug 01, 2008 6:07 am
Post
by ardan16 » Fri Oct 23, 2009 7:29 pm
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.
requinix
Spammer :|
Posts: 6617 Joined: Wed Oct 15, 2008 2:35 am
Location: WA, USA
Post
by requinix » Fri Oct 23, 2009 7:53 pm
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.
ardan16
Forum Commoner
Posts: 32 Joined: Fri Aug 01, 2008 6:07 am
Post
by ardan16 » Fri Oct 23, 2009 8:03 pm
Thanks tasairis,
Like I said, I spent way too long looking at it.