wispas Posted February 8, 2010 Share Posted February 8, 2010 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 } ?> Quote Link to comment https://forums.phpfreaks.com/topic/191336-missing-1-row-every-time-sql-query/ Share on other sites More sharing options...
PFMaBiSmAd Posted February 8, 2010 Share Posted February 8, 2010 $row=mysql_fetch_assoc($result); The above line of code, before the start of your loop, is fetching and discarding the first row from the result set. Why is that line of code in your program? Quote Link to comment https://forums.phpfreaks.com/topic/191336-missing-1-row-every-time-sql-query/#findComment-1008758 Share on other sites More sharing options...
wispas Posted February 8, 2010 Author Share Posted February 8, 2010 you are absolutely right... i dont know why that is there... took it out now... all working well. Quote Link to comment https://forums.phpfreaks.com/topic/191336-missing-1-row-every-time-sql-query/#findComment-1008767 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.