Jump to content

Missing 1 row every time... SQL Query


wispas

Recommended Posts

I have written a SQL query that for some reason will miss out 1 row...

for example i have 8 results with a city_code of AUH

 

this will display properly when putting the SQL query in PHPMyAdmin, but when done in PHP it will only show 7....

 

Can anyone figure out why it will do this...?

 

SQL:

<?php
// Connect database
include("includes/connectdb.php");
?>

<?php
// get value of id that sent from address bar
$id=$_GET['id'];
// Get records in all columns from table where column id equal in $id and put it in $result.
$result=mysql_query("

SELECT *
FROM city
INNER JOIN hotel
ON hotel.hotel_city_code = city.city_code
WHERE city_id='$id'

");
// Split records in $result by table rows and put them in $row.
$row=mysql_fetch_assoc($result);
// Close database connection.
mysql_close();
?>

 

Displaying all of the hotels:

<?php
while($row=mysql_fetch_array($result)){
?>
<table width="325" border="0" cellspacing="0" cellpadding="0">
        <tr>
          <td width="125" align="left" valign="top"><?php echo '<img src="'.$row['hotel_img'].'" />'; ?></td>
          <td width="200" align="left" valign="top"><div id="hotel_name"><?php echo $row['hotel_name']; ?><br />
      <?php for($i = 0; $i < $row['hotel_star']; $i++)
    echo '<img src="images/star.gif" alt=""/>';   ?></div>
          <div id="hotel_address"><?php echo $row['hotel_address']; ?></div>
          <div id="hotel_desc"><?php echo  nl2br( substr($row['hotel_desc'], 0, 65 )) . "..." ; ?></div></td>
        </tr>
</table>
<br/>
<?php
}
?>

Link to comment
https://forums.phpfreaks.com/topic/191336-missing-1-row-every-time-sql-query/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.