Jump to content

PHP Join 3 MySQL statements to just one.


Daniel_Hatcher

Recommended Posts

This is the code i have.

 

			$select_types = db_query("SELECT tid FROM {term_data} WHERE vid=$id");	
		while ($term = db_fetch_object($select_types)) 
		{

		$select_types2 = db_query("SELECT b.title, b.nid FROM {term_node} n INNER JOIN {node} b on n.nid=b.nid WHERE n.tid=$term->tid AND b.status=1");
		if (mysql_num_rows($select_types2)==0) return 'No tutorials found for this category.';	
		while ($term2 = db_fetch_object($select_types2)) 
		{

		$result = db_query("SELECT nid, description FROM {tutorial} WHERE nid='$term2->nid' AND parent=0");	
		$term3 = db_fetch_object($result);

 

Now i wan't to join all 3 together with JOINS only i can't get it to work it shows the rows about 30 time.

Link to comment
Share on other sites

I have this code

 

SELECT 
a.tid,c.title, c.nid, d.description 
FROM 
{term_data} a INNER JOIN {term_node} b INNER JOIN {node} c INNER JOIN {tutorial} d 
ON 
d.nid=c.nid 
WHERE 
a.vid=$id AND b.tid=a.tid AND c.status=1 AND d.parent=0

 

Only it displays

 

Creating contact form

Example Expert

ok intermediate

aghh intermediate

Creating contact form

Example Expert

ok intermediate

aghh intermediate

Creating contact form

Example Expert

ok intermediate

aghh intermediate

Creating contact form

Example Expert

ok intermediate

aghh intermediate

Creating contact form

Example Expert

ok intermediate

aghh intermediate

 

So you can see it repeats.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

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.