Reputation: 61
I have this code
$result = mysql_query("SELECT name from room");
$data = mysql_fetch_array($result);
$firstValue="";
while($data = mysql_fetch_array($result)){
if($firstValue==""){
$firstValue=$data['name'];
}
if(isset($_POST["occupant"])and trim($_POST["choice"])==$data['name']){
echo '<option selected="selected" value="'.$data['name'].'" >'.$data['name'];
echo '</option>';
}else
{
echo '<option value="'.$data['name'].'" >'.$data['name'];
echo '</option>';
}
}
What i want here is to show all data from my database but when i open it in browser shows only the second data down to the last data. And i wonder why the first data is missing. Can anybody knows my mistake here?
Upvotes: 0
Views: 46
Reputation: 219824
Get rid of the first:
$data = mysql_fetch_array($result);
It is popping the first record off of your result set.
$result = mysql_query("SELECT name from room");
$firstValue="";
while($data = mysql_fetch_array($result)){
Upvotes: 2