Topic: add new field to lengthy dbquery (Read 1311 times)
aka J Love Community Supporter?
Bill Gates is my home boy
Gender:
Posts: 884
1636 credits Members referred : 4
« on: Aug 23, 2006, 08:48:59 PM »
trying to add to this PHP mysql db query (thats why i posted here, its written in php form)
i want to make it so this very same "$result" will find the "user_clanrank" field from the db fusion_users aka $dbprefix_users... but i cant get it to work, if you understand my problem take a look:
Code:
<?php $result = dbquery( "SELECT t.*, COUNT(p.post_id) AS thread_replies, tu1.user_name AS user_author, tu2.user_name AS user_lastuser FROM ".$db_prefix."threads t LEFT JOIN ".$db_prefix."posts p USING(thread_id) LEFT JOIN ".$db_prefix."users tu1 ON t.thread_author = tu1.user_id LEFT JOIN ".$db_prefix."users tu2 ON t.thread_lastuser = tu2.user_id WHERE t.forum_id='$forum_id' AND thread_sticky='1' GROUP BY thread_id ORDER BY thread_lastpost DESC" ); ?>
Global Moderator Community Supporter?
Jedai Sword Master
Gender:
Posts: 6280
38506 credits Members referred : 374
It's time to use PHP5!
« Reply #1 on: Aug 23, 2006, 09:40:51 PM »
first, this is a MySQL question (move the post you're a mod too)
You have to debug the sql statement, just "echo" the statement and place the sql into the sql textarea inside phpmyadmin an see what happens (post the error if you get one...)
aka J Love Community Supporter?
Bill Gates is my home boy
Gender:
Posts: 884
1636 credits Members referred : 4
« Reply #2 on: Aug 24, 2006, 12:24:41 AM »
well nothin happens when i run the statement above, this is because it is stock and unchanged.. so it will not error, and it will grab all the data necessary, i just want to add to it so it finds the user_Clanrank from users table as well
Global Moderator Community Supporter?
Jedai Sword Master
Gender:
Posts: 6280
38506 credits Members referred : 374
It's time to use PHP5!
« Reply #3 on: Aug 24, 2006, 01:11:53 AM »
Nick said this before its difficult to help you without knowing the appliaction but try this:
"SELECT t.*, COUNT(p.post_id) AS thread_replies, tu1.user_name AS user_author, tu1.user_Clanrank AS clan_rank, tu2.user_name AS user_lastuser FROM ".$db_prefix."threads t LEFT JOIN ".$db_prefix."posts p USING(thread_id) LEFT JOIN ".$db_prefix."users tu1 ON t.thread_author = tu1.user_id LEFT JOIN ".$db_prefix."users tu2 ON t.thread_lastuser = tu2.user_id WHERE t.forum_id='$forum_id' AND thread_sticky='1' GROUP BY thread_id ORDER BY thread_lastpost DESC"
aka J Love Community Supporter?
Bill Gates is my home boy
Gender:
Posts: 884
1636 credits Members referred : 4
« Reply #4 on: Aug 24, 2006, 04:21:43 AM »
nope didnt work.. here is entire page code if it helps, you can find this DBquery in the page twice.
Code:
<?php require_once "../maincore.php"; require_once BASEDIR."subheader.php"; include LOCALE.LOCALESET."forum/main.php"; include BASEDIR."colors2.php"; if (!isset($lastvisited) || !isNum($lastvisited)) $lastvisited = time(); $threads_per_page = 20;
if (!FUSION_QUERY || !$forum_id || !isNum($forum_id)) fallback("index.php");
$result = dbquery( "SELECT f.*, f2.forum_name AS forum_cat_name FROM ".$db_prefix."forums f LEFT JOIN ".$db_prefix."forums f2 ON f.forum_cat=f2.forum_id WHERE f.forum_id='".$forum_id."'" ); if (dbrows($result)) { $data = dbarray($result); if (!checkgroup($data['forum_access']) || !$data['forum_cat']) fallback("index.php"); } else { fallback("index.php"); } $can_post = checkgroup($data['forum_posting']);
$rows = dbrows(dbquery("SELECT * FROM ".$db_prefix."threads WHERE forum_id='$forum_id' AND thread_sticky='0'")); if (!isset($rowstart) || !isNum($rowstart)) $rowstart = 0;
if ($rowstart == 0) { $result = dbquery( "SELECT t.*, COUNT(p.post_id) AS thread_replies, tu1.user_name AS user_author, tu1.user_Clanrank AS user_clanrank, tu2.user_name AS user_lastuser FROM ".$db_prefix."threads t LEFT JOIN ".$db_prefix."posts p USING(thread_id) LEFT JOIN ".$db_prefix."users tu1 ON t.thread_author = tu1.user_id LEFT JOIN ".$db_prefix."users tu2 ON t.thread_lastuser = tu2.user_id WHERE t.forum_id='$forum_id' AND thread_sticky='1' GROUP BY thread_id ORDER BY thread_lastpost DESC"
if ($rows != 0) { $result = dbquery( "SELECT t.*, COUNT(p.post_id) AS thread_replies, tu1.user_name AS user_author, tu1.user_Clanrank AS user_clanrank, tu2.user_name AS user_lastuser FROM ".$db_prefix."threads t LEFT JOIN ".$db_prefix."posts p USING(thread_id) LEFT JOIN ".$db_prefix."users tu1 ON t.thread_author = tu1.user_id LEFT JOIN ".$db_prefix."users tu2 ON t.thread_lastuser = tu2.user_id WHERE t.forum_id='$forum_id' AND thread_sticky='1' GROUP BY thread_id ORDER BY thread_lastpost DESC"