0

im trying a basic thing but there is some problem with my query, Im trying to populate names in a dropdown where status = Arrived, however the query doesn't work with where clause, neither giving any syntax error. Here is my code:

$sql= mysqli_query($con,"Select name from reservations where status='Arrived'"); 
$result=mysqli_fetch_assoc($sql);
echo "<select name=\"name\">"; 
while($row = mysqli_fetch_array($sql)) 
{        
echo "<option value='".$row['name']."'>".$row['name']."</option>"; 
}
echo "</select>";
?>
reticent23
  • 11
  • 4
  • 1
    Not working in what way? No options are populated? Here's a thorough [guide](https://stackoverflow.com/a/22662582/4205384) on debugging `mysqli` related problems. – El_Vanja Dec 05 '20 at 10:44
  • I mean when I put "where" in the query, it doesn't populate the values in drop down, else it does show all the names in the list. But since I want only those names having specific status, that's why I have to use "where " clause.Thanks – reticent23 Dec 05 '20 at 11:50
  • And if you run this query directly on your database, does it return any records? – El_Vanja Dec 05 '20 at 11:52
  • Yes,it does, when i run this directly on my database. – reticent23 Dec 05 '20 at 11:53
  • 1
    If `mysqli` is showing no errors, then something in your question is misrepresented. Are you sure you're running an *identical* query on your db? Is `'Arrival'` really hardcoded? – El_Vanja Dec 05 '20 at 12:21
  • 'Arrived' is hard coded, even if i run the query on db with any other status which exists in db, it shows results, but not on my page, it simply shows empty drop down. – reticent23 Dec 05 '20 at 13:08
  • It might be a problem with case. Have you tried with `'arrived'`? – El_Vanja Dec 05 '20 at 13:41
  • but in db, value exists with captial A. – reticent23 Dec 05 '20 at 14:13
  • Then I am at a loss. Without a reproducible example, I have no other ideas why this would fail. – El_Vanja Dec 05 '20 at 14:16
  • I figured out the issue, basically the row entry against the Arrived status wasn't complete, and there was only one value with this status, hence it wasn't picking anything in drop down, when i checked query with other status, it worked, so it gave me the hint that my query is correct, only issue was with the entries against Arrived status, thanks anyway. – reticent23 Dec 05 '20 at 14:54

0 Answers0