Hi

I am creating an basic online menu ordering system, what i want to do is display the typical chilli level, vegetarian and nut icons/symbols along side a dish name.

I have a product table which has all the required field which will be called out.

spice level, veg and nut is stored as enum on sql database.

Spice = '0','1','2','3' representing: none, mild, medium and hot
vegetarian = '0','1' representing: Not Suitable for, and Suitable
nut = '0','1' representing: nut free, and contains nut
--------------------

At the moment it does display like the above but when i try to replace the numbers with images it doesn't display anything.

I created this within a function.

function product_starter(){
	$get = mysql_query('SELECT * FROM products INNER JOIN categories ON categories.c_id = products.c_id WHERE categories.c_id = 1 ORDER BY p_id ASC');
	if (mysql_num_rows($get) == 0) {
	echo "There are no products available!";
	}
	else{
		while ($get_row = mysql_fetch_assoc($get))
$veg="";
	$nut="";	
	$spice="";
	if ($p_spice == "1"){
		$spice='<img src="../Resources/chili.png" width="16" height="16" alt="chilli" />';
	}else if($p_spice == "2"){
		$spice='<img src="../Resources/chili.png" width="16" height="16" alt="chilli" /> <img src="../Resources/chili.png" width="16" height="16" alt="chilli" />';
	} else if ($p_spice == "3"){
		$spice='<img src="../Resources/chili.png" width="16" height="16" alt="chilli" /> <img src="../Resources/chili.png" width="16" height="16" alt="chilli" /> <img src="../Resources/chili.png" width="16" height="16" alt="chilli" />';
	}
		if ($p_veg == "0"){
		$veg='';
	}else if($p_veg == "1"){
		$veg='<img src="../Resources/veg.png" width="16" height="16" alt="chilli" /> <img src="../Resources/chili.png" width="16" height="16" alt="chilli" />';
	}
		if ($p_allergy == "0"){
		$nut='';
	}else if($p_allergy == "1"){
		$nut='<img src= src="../Resources/nut.png" width="16" height="16" alt="chilli" /> <img src="../Resources/chili.png" width="16" height="16" alt="chilli" />';
	}



		echo '<table width="500" border="0" style="margin-bottom: 5px;">
		
  <tr>
    <td colspan="2" width="400">'.$get_row['p_name'].''.$veg.'' .$spice. ''.$nut.'</td>
    <td width="100">'.number_format($get_row['p_price'], 2).' <a href="cart.php?add='.$get_row['p_id'].'">Add</a></td>
  </tr>
  <tr>
    <td width="350" colspan="2">'.$get_row['p_desc'].'</td>
	<td width="100"></td>
  </tr>
</table>';
	}
}

Recommended Answers

All 3 Replies

Where do the $p_spice, $p_veg and $p_allergy that you use as conditions in your if statements come from? Shouldn't they be a part of the $row array (like $row)?

I presume the paths to images are OK. There is an error in line 26 where you say

$nut='<img src= src="../Resources/nut.png" ...

These kind of errors happen when copying/pasting. Similar is with your alt="chilli" within each of img tags (even though the image is veg.png or nut.png).

Where do the $p_spice, $p_veg and $p_allergy that you use as conditions in your if statements come from? Shouldn't they be a part of the $row array (like $row)?

I presume the paths to images are OK. There is an error in line 26 where you say

$nut='<img src= src="../Resources/nut.png" ...

These kind of errors happen when copying/pasting. Similar is with your alt="chilli" within each of img tags (even though the image is veg.png or nut.png).

I made those amendedments.

if ($get_row['p_spice'] == "1"){
		$spice='<img src="../Resources/chili.png" width="16" height="16" alt="chilli" />';
	}else if($get_row['$p_spice'] == "2"){
		$spice='<img src="../Resources/chili.png" width="16" height="16" alt="chilli" /> <img src="../Resources/chili.png" width="16" height="16" alt="chilli" />';
	} else if ($get_row['$p_spice'] == "3"){
		$spice='<img src="../Resources/chili.png" width="16" height="16" alt="chilli" /> <img src="../Resources/chili.png" width="16" height="16" alt="chilli" /> <img src="../Resources/chili.png" width="16" height="16" alt="chilli" />';
	} else if ($get_row['$p_spice'] == "0"){
		$spice='';
	}

Theres little progress, the first dish SPICE LEVEL displays but the actual dish itself and other dishes dont appear.

I believe it maybe overwriting it or something but i cant figure it out.

Any Suggestions

Found the problem, needed to add the curly brackets within the while loop.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.