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
https://forums.phpfreaks.com/topic/213743-joins/
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
https://forums.phpfreaks.com/topic/213743-joins/#findComment-1112519
Share on other sites

Archived

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

×
×
  • 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.