Jump to content

joins


woodplease

Recommended Posts

i think this is in the right section.

 

i have two table, each with a date field, and i'm trying to join them so that i can echo out the most rescent date of the two tables.

i have some code but i'm not sure if the sql is correct, as nothing is being displayed.

		$join =mysql_query("SELECT topic.section_sub_id, topic.date, post.section_sub_id, post.date FROM topic LEFT JOIN post ON topic.section_sub_id=post.section_sub_id WHERE post.section_sub_id = " .$row2['section_sub_id']. " ORDER BY topic.date") or die("Select Error :" . mysql_error());
	$latest= mysql_fetch_assoc($join);
	echo $latest['post.date'];

 

my tables are

 

TOPIC

topic_id

topic _name

section_sub_id

date

 

POST

post_id

post_name

section_sub_id

date

 

any help would be great

 

Link to comment
Share on other sites

Hi

 

The function mysql_fetch_assoc returns an associative array. The keys for the associative array will have the column names prefixed with the table name. As you have 2 columns called date give them an alias name to refer to them and use that to get the element from the associative array.

 

If you are unsure, use print_r($latest); and see what the elements of the array are called.

 

All the best

 

Keith

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.