Jump to content

First row doesnt echo?


dezkit

Recommended Posts

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 />";
}
}


?>

Link to comment
https://forums.phpfreaks.com/topic/198344-first-row-doesnt-echo/
Share on other sites

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.

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.