Forum Moderators: coopster
¦id¦name ¦info¦catid¦published¦
+--+------+----+-----+---------+
¦1 ¦name1 ¦bla ¦1 ¦0 ¦
etcetera.
ID is just for id of table name is name of product info in just info :D. catid stand for category-id wich should exist in another table published is just if it is published or not.
The other table:
¦id¦name ¦info¦published¦
+--+---------+----+---------+
¦1 ¦catname1 ¦bla ¦0 ¦
I want a query to loop all products this is not hard for me (Its damn easy):
$result = mysql_query("SELECT * FROM mos_mediaman_products");
now i need to do another query in the result doing something like:
select * from mos_mediaman_category WHERE id == $row['catid']; and after echoing the result the first query just collaps.
Here is my code i tried:
plz take a look:
<?
if (!isset($_GET['type']))
{
header("Location: index2.php?option=com_mediaman&mosmsg=ERROR: Something wierd happened did you follow the menu link?");
}
if ($_GET['type'] == 'product')
{
$pagename = "products";
$v1 ="name";
$v2 ="Category";
$v3 ="Published";
$result = mysql_query("SELECT * FROM mos_mediaman_products");
}
?>
<table class="adminheading">
<tr><th>Manage Media - Add <?echo "$pagename";?></th></tr>
</table>
<table width="600" class="adminform">
<tr>
<th width="20">#</th>
<th align="left" style="white-space:nowrap;"><?php echo "$v1"?></th>
<th align="left" style="white-space:nowrap;"><?php echo "$v2"?></th>
<th align="left" style="white-space:nowrap;" width="10"><?php echo "$v3"?></th>
</tr><?while ($row = mysql_fetch_array($result)){?>
<tr>
<td><?echo $row['id'];?></td>
<td><?echo $row['name'];?></td>
<?
IF ($_GET['type'] == 'product')
{$rresult = mysql_query("SELECT name FROM mos_mediaman_category WHERE id == ". $row['catid'] ."");}
while ($rrow = mysql_fetch_array($result)){
?>
<td><?echo $rrow['name'];}?></td>
<td></td>
</tr>
<?}?>
<tr>
<th width="" colspan="4">.</th>
</tr>
</table>
Example
$result = mysql_query("SELECT mos_mediaman_products.id, mos_mediaman_products.name, mos_mediaman_products.catid, mos_mediaman_category.name FROM mos_mediaman_products, mos_mediaman_category where id='10' AND mos_mediaman_products.catid=mos_mediaman_category.id");
This query should return:
Products: ID - NAME - CATID + Category: NAME
Done on the fly! To be tested!
Tomda