dezkit Posted April 13, 2010 Share Posted April 13, 2010 hey guys, i have this code, but i cant ever seem to get the first row to echo with the others, im stumbled why it wont' echo. thank you and please help me fix my code. <?php mysql_connect("localhost", "root", "") or die(mysql_error()); mysql_select_db("menu") or die(mysql_error()); $url = $_GET["groupid"]; if(isset($url)){ $query1 = "SELECT * FROM `menu` WHERE `groupid` = '".$url."'"; $query2 = "SELECT * FROM `groups` WHERE `id` = '".$url."'"; $result1 = mysql_query($query1) or die(mysql_error()); $result2 = mysql_query($query2) or die(mysql_error()); if(mysql_num_rows($result1)){ $row1 = mysql_fetch_array($result1); $row2 = mysql_fetch_array($result2); echo "<table width=\"100%\">"; echo "<tr><td></td>"; if($row2["set"] == "0" && $row2["drink"] == "" && !$row2["id"] == "14"){ echo "<td>Price</td></tr>"; } if($row2["set"] == "0" && $row2["drink"] == "1"){ echo "</tr>"; } if($row2["set"] == "1"){ echo "<td>Small</td><td>Medium</td><td>Large</td></tr>"; } if($row2["set"] == "0"){ while($row1 = mysql_fetch_array($result1)){ echo "<tr><td><b>".$row1['product']."</b><br><font size='-1'>".$row1['description']."</font></td><td>"; if($row2["drink"] == ""){ echo "$"; } echo $row1["price"]."</td></tr>"; } } if($row2["set"] == "1"){ while($row1 = mysql_fetch_array($result1)){ echo "<tr><td><b>".$row1['product']."</b><br><font size='-1'>".$row1['description']."</font></td><td>"; if($row1["id"] == "99"){ echo ""; } else { echo "$".$row2['small']; } echo "</td><td>"; if(!$row2['medium'] == ""){ echo "$"; } echo $row2['medium']."</td><td>$".$row2['large']."</td></tr>"; } } echo "</table>"; if(!$row2["text"] == ""){ echo "<br><br><i>".$row2["text"]."</i>"; } } } else { $query = "SELECT * FROM `groups` ORDER BY `groups`.`group` ASC"; $result = mysql_query($query) or die(mysql_error()); while($row = mysql_fetch_array($result)){ echo "<a href='?groupid={$row['id']}'>{$row['group']}</a>"; echo "<br />"; } } ?> Quote Link to comment https://forums.phpfreaks.com/topic/198344-first-row-doesnt-echo/ Share on other sites More sharing options...
dezkit Posted April 13, 2010 Author Share Posted April 13, 2010 problem solved; removed $row1 = mysql_fetch_array($result1); thanks nobody Quote Link to comment https://forums.phpfreaks.com/topic/198344-first-row-doesnt-echo/#findComment-1040727 Share on other sites More sharing options...
trq Posted April 13, 2010 Share Posted April 13, 2010 Your calling mysql_fetch_array outside of your loop. This returns an array and moves the result resource pointer 1 row forward. Quote Link to comment https://forums.phpfreaks.com/topic/198344-first-row-doesnt-echo/#findComment-1040728 Share on other sites More sharing options...
Ken2k7 Posted April 13, 2010 Share Posted April 13, 2010 You're calling mysql_fetch_array on $row1 twice, so you skipped the first result. One solution is to reset it. Before the while loop, put this: mysql_data_seek($row1, 0); That should solve it. For the record, you are looping $row1 twice. Is that intentional? If so, you will want to put that code above before both while loops. Quote Link to comment https://forums.phpfreaks.com/topic/198344-first-row-doesnt-echo/#findComment-1040729 Share on other sites More sharing options...
dezkit Posted April 13, 2010 Author Share Posted April 13, 2010 yeah i got it guys, thank you. ;P Quote Link to comment https://forums.phpfreaks.com/topic/198344-first-row-doesnt-echo/#findComment-1040730 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.