Jump to content

Archived

This topic is now archived and is closed to further replies.

jjdave

PHP Query Question....

Recommended Posts

Hi All, any help will be appriciated. Thanks.
I am trying to JOIN 3 Tables (X & Y & Z) with 1 Column (partlist_id) and my query does not work. I can not print the results.
[code=php:0]$query="SELECT x.id, x.assy_part,
  y.part_no, y.part_desc, 
  z.roll_id,  z.roll_image
  FROM `$table_name` as x 
  INNER JOIN `$vpt_table_partlist` as y ON y.partlist_id = x.partlist_id
  INNER JOIN `$vpt_table_rollover` as z ON z.partlist_id = x.partlist_id";
$result=mysql_query($query);
$num=mysql_numrows($result);

echo "<TD><br>";
$i=0;
while ($i < $num) {
  $id=mysql_result($result,$i,"id");
  $part_no=mysql_result($result,$i,"part_no");
      echo "$id : $part_no";
  $i++;
}
echo "</TD></TR>";[/code]


If I remove Table Z and only JOIN Table X & Y, with following code, then it works fine.
[code=php:0]$query="SELECT x.id, x.assy_part, y.part_no, y.part_desc
  FROM `$table_name` as x 
  INNER JOIN `$vpt_table_partlist` as y ON y.partlist_id = x.partlist_id";
$result=mysql_query($query);
$num=mysql_numrows($result);

echo "<TD><br>";
$i=0;
while ($i < $num) {
  $id=mysql_result($result,$i,"id");
  $part_no=mysql_result($result,$i,"part_no");
      echo "$id : $part_no";
  $i++;
}
echo "</TD></TR>";[/code]

Share this post


Link to post
Share on other sites
Sounds like there are no records in z where z.partlist_id = x.partlist_id

Share this post


Link to post
Share on other sites

×

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.