Jump to content

[SOLVED] only echoes one result?


blueman378

Recommended Posts

hi guys, well heres the code *snippet*

 

	public function view_prod($cid) // ADD A NEW PRODUCT
{
	echo "<table border=\"1\">
	<tr>
		<td><strong>Product Name</strong></td>
		<td><strong>Product Description</strong></td>
		<td><strong>Product Picture</strong></td>
		<td><strong>Product Price</strong></td>
		<td><strong>Product Instock</strong></td>
		<td><strong>Product Category</strong></td>
		<td><strong>Actions</strong></td>
	</tr>
	";
	if(isset($cid) && $cid != 0)
	{
		$query = mysql_query("SELECT * FROM products WHERE cid='$cid'") or die(mysql_error());
	}
	else
	{
		$query = mysql_query("SELECT * FROM products") or die(mysql_error());
	}
	while ($products = mysql_fetch_array($query))
	{
		echo "
		<tr>
			<td valign=\"top\">$products[Name]</td>
			<td valign=\"top\">$products[Description]</td>
			<td valign=\"top\"><a href=\"../pictures/Fulls/$products[image]\">
			<img border=\"0\" src=\"../pictures/Thumbs/$products[image]\"></a></td>
			<td valign=\"top\">$products[Cost]</td>
			<td valign=\"top\">$products[Quantity]</td>";
			$query = mysql_query("SELECT * FROM sub_categories WHERE id='$products[cid]'") or die(mysql_error());
			$row = mysql_fetch_assoc($query);
			$subcat = $row[Name];
			$query = mysql_query("SELECT * FROM main_categories WHERE id='$row[mid]'") or die(mysql_error());
			$row = mysql_fetch_assoc($query);
			$maincat = $row[Name];
			echo"<td valign=\"top\">$maincat >> $subcat</td>
			<td valign=\"top\">none</td>
		</tr>
		";
	}
	echo "</table>";
}

 

so it should echo eg all prodcuts from fruit when you select the fruit category but it is only echoing one result and then stopping, any ideas?

Link to comment
https://forums.phpfreaks.com/topic/108681-solved-only-echoes-one-result/
Share on other sites

They don't need their own variables, they can be re-used time and time again.

I can see one problem:

 

$products[Name]

 

The declaration of array key's should contain quotes if it's a string. Otherwise PHP will iterate through every possible key, and when it doesn't exist it will finally determine that the key you gave it is in fact a string. A long process :D

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.