hisham
IS-IT--Management
- Nov 6, 2000
- 194
I have tow tables:
category “ id, name “ and
items: “id, cid, name, details”
where cid in items table = id in category table
and I use the following code to display all category with links to the related items:
<?
$cat = "SELECT * FROM category ";
$result = mysql_query($cat);
$num=mysql_num_rows($result);
for($i=0;$i<$num;$i++){
$row = mysql_fetch_row($result);
echo"<ahref=\"items.php?sid=$row[0]\">$row[2]</a>";
}
?>
now. How can I display the name of the category related in the items.php:
<?
$query = mysql_query("SELECT * FROM items WHERE id='$id'"
$row = mysql_fetch_row($query);
echo "$row[2]";
echo "$row[3]";
?>
category “ id, name “ and
items: “id, cid, name, details”
where cid in items table = id in category table
and I use the following code to display all category with links to the related items:
<?
$cat = "SELECT * FROM category ";
$result = mysql_query($cat);
$num=mysql_num_rows($result);
for($i=0;$i<$num;$i++){
$row = mysql_fetch_row($result);
echo"<ahref=\"items.php?sid=$row[0]\">$row[2]</a>";
}
?>
now. How can I display the name of the category related in the items.php:
<?
$query = mysql_query("SELECT * FROM items WHERE id='$id'"
$row = mysql_fetch_row($query);
echo "$row[2]";
echo "$row[3]";
?>