Jump to content

Recommended Posts

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

Link to comment
https://forums.phpfreaks.com/topic/241703-how-to-use-joined-querys/
Share on other sites

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

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 :).

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'];

}
?>

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

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