Aureole Posted January 26, 2008 Share Posted January 26, 2008 I have these two queries, I'm pretty sure it'd be possible to do this with only one query but I can't really think how. Any ideas? <?php $queryA = "SELECT `forum_name`, `forum_id`, `forum_parent_id` FROM `forums` INNER JOIN `topics` ON `topics` . `topic_parent_id` = `forums` . `forum_id` WHERE `topic_id` = '{$_GET['id']}'"; $resultA = mysql_query( $queryA ); $assocA = mysql_fetch_assoc( $resultA ); $queryB = "SELECT `cat_name`, `cat_id` FROM `categories` WHERE `cat_id` = '{$assocA['forum_parent_id']}'"; $resultB = mysql_query( $queryB ); $assocB = mysql_fetch_assoc( $resultB ); ?> Quote Link to comment https://forums.phpfreaks.com/topic/87861-solved-query-question/ Share on other sites More sharing options...
revraz Posted January 26, 2008 Share Posted January 26, 2008 JOIN catergories ON (cat_id=forum_parent_id) Quote Link to comment https://forums.phpfreaks.com/topic/87861-solved-query-question/#findComment-449472 Share on other sites More sharing options...
hitman6003 Posted January 26, 2008 Share Posted January 26, 2008 Just create another join.... SELECT forum_name, forum_id, forum_parent_id, cat_name, cat_id FROM forums INNER JOIN topics ON topics.topic_parent_id = forums.forum_id JOIN categories c ON c.cat_id = fourms.forum_parent_id WHERE topic_id = '{$_GET['id']}' Quote Link to comment https://forums.phpfreaks.com/topic/87861-solved-query-question/#findComment-449479 Share on other sites More sharing options...
Aureole Posted January 26, 2008 Author Share Posted January 26, 2008 Thanks a lot, I didn't know you could do more than one join at a time like that. Quote Link to comment https://forums.phpfreaks.com/topic/87861-solved-query-question/#findComment-449494 Share on other sites More sharing options...
revraz Posted January 26, 2008 Share Posted January 26, 2008 You can do as many as you need/like. Quote Link to comment https://forums.phpfreaks.com/topic/87861-solved-query-question/#findComment-449495 Share on other sites More sharing options...
hitman6003 Posted January 26, 2008 Share Posted January 26, 2008 You can do as many as you need/like. Close...61 is the max...but if you're doing 61 joins I think you need to do some serious thinking about a database redesign. http://dev.mysql.com/doc/refman/5.0/en/joins-limits.html Quote Link to comment https://forums.phpfreaks.com/topic/87861-solved-query-question/#findComment-449527 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.