I have a DB (quartos) created with the following structure:
id_quarto tipo_quarto vista_quarto |
a Single Mar |
b Single Mar |
c Single Mar |
d Single Serra |
I want it to return the results of id_quarto, when tipo_quarto=Single and vista_quarto=Mar which values come from a form.
So i write the following:
$strSQL = "
SELECT id_quarto
FROM quartos
WHERE tipo_quarto='". $_POST['tipo_quarto'] ."'
AND vista_quarto='". $_POST['vista_quarto'] ."'";
$rs = mysql_query($strSQL);
$row = mysql_fetch_array($rs);
Then i loop it and write in a table as followed:
while($row = mysql_fetch_array($rs)) {
<?
<table border="1">
<tr align="left">
<td width="75"><?php echo $row['id_quarto']; ?></td>
</tr>
</table>
The problem here is that it does not return the id_quarto=a , only b and c. Why is that and what can i do to fix it?
Thanks.
You have extra
$row = mysql_fetch_array($rs);just aftermysql_query($strSQL);. Then inwhileloop you read$rowagain (second row in resultset).So your code will look
Also, it always makes sense to add code for handling mysql errors.