Andy11548 Posted July 11, 2011 Share Posted July 11, 2011 Just a quick question, I got told I should use joined querys, how would I use this query? SELECT * FROM `forum_cats` AS cats, `forum_subs` AS subs, `forum_topics` AS topics, `forum_replys` AS replys, `users` AS users WHERE subs.cat=cats.name AND topics.sub_cat_id=subs.id AND replys.sub_cat_id=subs.id AND users.username=replys.username ORDER BY cats.id ASC, replys.id DESC Quote Link to comment https://forums.phpfreaks.com/topic/241703-how-to-use-joined-querys/ Share on other sites More sharing options...
Adam Posted July 11, 2011 Share Posted July 11, 2011 Just like any other query? Quote Link to comment https://forums.phpfreaks.com/topic/241703-how-to-use-joined-querys/#findComment-1241364 Share on other sites More sharing options...
Andy11548 Posted July 11, 2011 Author Share Posted July 11, 2011 Well, I get this error... Warning: mysql_fetch_assoc() expects parameter 1 to be resource, string given in C:\wamp\www\test.php on line 6 OR Warning: mysql_fetch_array() expects parameter 1 to be resource, string given in C:\wamp\www\test.php on line 6 Quote Link to comment https://forums.phpfreaks.com/topic/241703-how-to-use-joined-querys/#findComment-1241367 Share on other sites More sharing options...
gristoi Posted July 11, 2011 Share Posted July 11, 2011 how exactly are you trying to execute the query? Quote Link to comment https://forums.phpfreaks.com/topic/241703-how-to-use-joined-querys/#findComment-1241368 Share on other sites More sharing options...
Andy11548 Posted July 11, 2011 Author Share Posted July 11, 2011 The only way I know using mysql_query. I've not been able to find a tutorial on it, so I've been playing the guessing game with some help from people. Quote Link to comment https://forums.phpfreaks.com/topic/241703-how-to-use-joined-querys/#findComment-1241373 Share on other sites More sharing options...
gristoi Posted July 11, 2011 Share Posted July 11, 2011 ok, can you post complete example of a query you are trying to execute. Its a bit hard trying to help you when we cant see what can be causing the issue. there is only so much I can guess at Quote Link to comment https://forums.phpfreaks.com/topic/241703-how-to-use-joined-querys/#findComment-1241377 Share on other sites More sharing options...
Andy11548 Posted July 11, 2011 Author Share Posted July 11, 2011 Sure thing <?php session_start(); include './includes/mysql/connect.php'; $query = (" SELECT * FROM `forum_cats` AS cats, `forum_subs` AS subs, `forum_topics` AS topics, `forum_replys` AS replys, `users` AS users WHERE subs.cat = cats.name AND topics.sub_cat_id = subs.id AND replys.sub_cat_id = subs.id AND users.username = replys.username ORDER BY cats.id ASC , replys.id DESC ") or die(mysql_error()); $fetch = mysql_fetch_array($query); ?> It's on my test page so I never ruined the rest of my code, so thats litterally everything. I don't like this joined query stuff, haha . Quote Link to comment https://forums.phpfreaks.com/topic/241703-how-to-use-joined-querys/#findComment-1241383 Share on other sites More sharing options...
gristoi Posted July 11, 2011 Share Posted July 11, 2011 you havent executed the query. You need to execute the query to get the resource id THEN use any fetch commands to retrievfe the data. it should look something like this: <?php session_start(); include './includes/mysql/connect.php'; $query = (" SELECT * FROM `forum_cats` AS cats, `forum_subs` AS subs, `forum_topics` AS topics, `forum_replys` AS replys, `users` AS users WHERE subs.cat = cats.name AND topics.sub_cat_id = subs.id AND replys.sub_cat_id = subs.id AND users.username = replys.username ORDER BY cats.id ASC , replys.id DESC ") ; $result = mysql_query($query) or die(mysql_error()); while ($row = mysql_fetch_array($result)){ // output the results . ie $row['item1']; } ?> Quote Link to comment https://forums.phpfreaks.com/topic/241703-how-to-use-joined-querys/#findComment-1241388 Share on other sites More sharing options...
Andy11548 Posted July 11, 2011 Author Share Posted July 11, 2011 Wow, thats what being tired does to you, makes you miss stupid things like "mysql_query" out haha. I feel dumb, how the hell didn't I notice that? :S Thanks for noticing haha. ~Andy Quote Link to comment https://forums.phpfreaks.com/topic/241703-how-to-use-joined-querys/#findComment-1241394 Share on other sites More sharing options...
gristoi Posted July 11, 2011 Share Posted July 11, 2011 coding + tired = mistakes Quote Link to comment https://forums.phpfreaks.com/topic/241703-how-to-use-joined-querys/#findComment-1241395 Share on other sites More sharing options...
Andy11548 Posted July 11, 2011 Author Share Posted July 11, 2011 Yep, I normally stop coding when I'm tired, but I need something to keep me awake haha. Anyways mate, thanks for that. ~Andy Quote Link to comment https://forums.phpfreaks.com/topic/241703-how-to-use-joined-querys/#findComment-1241398 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.