woodplease Posted September 18, 2010 Share Posted September 18, 2010 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 Quote Link to comment https://forums.phpfreaks.com/topic/213743-joins/ Share on other sites More sharing options...
kickstart Posted September 18, 2010 Share Posted September 18, 2010 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 Quote Link to comment https://forums.phpfreaks.com/topic/213743-joins/#findComment-1112519 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.