We Must Design Posted June 20, 2007 Share Posted June 20, 2007 Hi I am creating a database of cocktails. If you have a look at www.wemustdesign.com/cocktail/index.php?section=view_cocktail&cocktail=Vodka_Boatman. In the section ingredients you can see that is says 1 part 1. Well this means that the cocktail has 1 part of 'ingredient' with the id 1 which is vodka. What I dont know how to do is to display the name of the 'ingredient' that refers to this id rather than displaying the id. Here is the code below: $query="SELECT * FROM cocktails WHERE name = '$cocktail_nor'"; $result=mysql_query($query); $num=mysql_numrows($result); $i=0;$i2=0; while ($i < $num) { $id=mysql_result($result,$i,"id"); $name=mysql_result($result,$i,"name"); $ingredients=mysql_result($result,$i,"ingredients"); $amounts=mysql_result($result,$i,"amounts"); echo "name: $name<br><br />"; $ingredients_explode=explode("|",$ingredients); $amounts_explode=explode("|",$amounts); $ingredients_count=count ($ingredients_explode); while ($i2<$ingredients_count){ echo"$amounts_explode[$i2] parts $ingredients_explode[$i2]<br />"; $i2++; } echo" <br />Glass: $glass<br /><br /> <br />Type/ Flavour: $type<br /><br /> <br />Difficulty: $difficulty<br /><br /> <br />Notes: $notes<br /><br /> "; $i++; } Link to comment https://forums.phpfreaks.com/topic/56417-solved-linking-tables/ Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.