Jump to content


Photo

PHP Query Question....


  • Please log in to reply
1 reply to this topic

#1 jjdave

jjdave
  • Members
  • Pip
  • Newbie
  • 6 posts

Posted 01 September 2006 - 06:56 PM

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.
$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>";


If I remove Table Z and only JOIN Table X & Y, with following code, then it works fine.
$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>";


#2 Barand

Barand
  • Moderators
  • Sen . ( ile || sei )
  • 18,021 posts

Posted 01 September 2006 - 07:45 PM

Sounds like there are no records in z where z.partlist_id = x.partlist_id
If you are still using mysql_ functions, STOP! Use mysqli_ or PDO. The longer you leave it the more you will have to rewrite.

Donations gratefully received






moon.png

|baaGrid| easy data tables - and more
|baaChart| easy line, column and pie charts




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users