ryandarin Posted March 5, 2007 Share Posted March 5, 2007 I think the code is fairly self explanatory, so i'll post that first. $query = "SELECT id,description,Title,tutorialtext,category," . "DATE_FORMAT(timeadded, '%Y-%m-%d') as date " . "FROM tutorial ORDER BY timeadded DESC LIMIT $max_items"; $query2 = "SELECT Name, catid," . "From tutorial_cats" $result = mysql_query ($query); while ($row = mysql_fetch_assoc ($result)) Im probably missing something simple, but how do I combine query and query2 togther so that it gets both the things from tutorial, and from tutorial_cats? Tell me if you need more info, or if im not making sense. Thanks alot , Ryan. Link to comment https://forums.phpfreaks.com/topic/41353-help-getting-info-from-two-mysql-tables-with-one-query/ Share on other sites More sharing options...
Barand Posted March 5, 2007 Share Posted March 5, 2007 $query = "SELECT t.id, t.description, t.Title, t.tutorialtext, t.category, c.Name DATE_FORMAT(t.timeadded, '%Y-%m-%d') as date FROM tutorial t INNER JOIN tutorial_cats c ON t.category = c.cat_id ORDER BY t.timeadded DESC LIMIT $max_items"; Link to comment https://forums.phpfreaks.com/topic/41353-help-getting-info-from-two-mysql-tables-with-one-query/#findComment-200372 Share on other sites More sharing options...
ryandarin Posted March 5, 2007 Author Share Posted March 5, 2007 Hmm, I added this, but then it gives me this error, its probably a stupid mistake by me, but this is the error. Warning: mysql_fetch_assoc(): supplied argument is not a valid MySQL result resource in /var/www/tutorialscript/index.php on line 21 Link to comment https://forums.phpfreaks.com/topic/41353-help-getting-info-from-two-mysql-tables-with-one-query/#findComment-200382 Share on other sites More sharing options...
Barand Posted March 5, 2007 Share Posted March 5, 2007 What does $result = mysql_query ($query) or die(mysql_error()); give? Link to comment https://forums.phpfreaks.com/topic/41353-help-getting-info-from-two-mysql-tables-with-one-query/#findComment-200385 Share on other sites More sharing options...
Barand Posted March 5, 2007 Share Posted March 5, 2007 nm, I forgot the comma at end of first line after c.Name Link to comment https://forums.phpfreaks.com/topic/41353-help-getting-info-from-two-mysql-tables-with-one-query/#findComment-200387 Share on other sites More sharing options...
ryandarin Posted March 6, 2007 Author Share Posted March 6, 2007 Heh, I think it was my mistake actually, I had one of the field names wrong . Thanks alot for you help I really appreciate it. Link to comment https://forums.phpfreaks.com/topic/41353-help-getting-info-from-two-mysql-tables-with-one-query/#findComment-200391 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.