TalkPHP
 
 
Account Login
Latest Articles
» The basic usage of PHPTAL, a XML/XHTML template library for PHP
» Vulnerable methods and the areas they are commonly trusted in.
» Simple way to protect a form from bot
» The Basics On: How Session Stealing Works
» How to keep your forms from double posting data
Advertisement
Associates
Associates
techtuts Darkmindz
CSS Tutorials Tutorialsphere.com - Free Online Tutorials
Boston PHP SurfnLearn
Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old 07-30-2008, 09:06 AM   #1 (permalink)
Orc
The Prestige
 
Orc's Avatar
 
Join Date: Dec 2007
Location: On your Hard Drive, hiding like a Virus
Posts: 888
Thanks: 168
Orc is on a distinguished road
Default More rows from join clauses

How can I get all the rows from a join clause? instead of 1?
__________________
Wax on, Wax off
Orc is offline  
Reply With Quote
Old 07-30-2008, 12:39 PM   #2 (permalink)
The Frequenter
 
Join Date: Dec 2007
Location: In my basement
Posts: 378
Thanks: 45
Aaron is on a distinguished road
Default

PHP Code:
$query "SELECT user.name, message.to".
"FROM user, message";
// I wonder if this would work... LIMIT count(*); 
__________________
Signatures are nothing but incriminating.
Send a message via MSN to Aaron
Aaron is offline  
Reply With Quote
Old 07-30-2008, 12:40 PM   #3 (permalink)
The Frequenter
 
Join Date: Dec 2007
Location: In my basement
Posts: 378
Thanks: 45
Aaron is on a distinguished road
Default

PHP Code:
$query "SELECT user.name, message.to".
"FROM user, message";
// I wonder if this would work... LIMIT count(*); 
Try that. I really don't use joins that much. The more queries the better.
__________________
Signatures are nothing but incriminating.
Send a message via MSN to Aaron
Aaron is offline  
Reply With Quote
Old 07-30-2008, 01:35 PM   #4 (permalink)
The Acquainted
 
CoryMathews's Avatar
 
Join Date: Nov 2007
Location: USA
Posts: 194
Thanks: 7
CoryMathews is on a distinguished road
Default

By default you should always get more then 1 if there is more then one. As long as you dont have a limit 1 on the end of the query. and aaron isnt that method really slow? (no backing on that statement)
CoryMathews is offline  
Reply With Quote
Old 07-30-2008, 06:07 PM   #5 (permalink)
The Frequenter
 
Join Date: Dec 2007
Location: In my basement
Posts: 378
Thanks: 45
Aaron is on a distinguished road
Default

Count is extremely slow. That was just something I was wondering about (it had no point whatsoever)

The only thing about my query was not using WHERE.
__________________
Signatures are nothing but incriminating.
Send a message via MSN to Aaron
Aaron is offline  
Reply With Quote
Old 07-30-2008, 08:31 PM   #6 (permalink)
Orc
The Prestige
 
Orc's Avatar
 
Join Date: Dec 2007
Location: On your Hard Drive, hiding like a Virus
Posts: 888
Thanks: 168
Orc is on a distinguished road
Default

Quote:
Originally Posted by CoryMathews View Post
By default you should always get more then 1 if there is more then one. As long as you dont have a limit 1 on the end of the query. and aaron isnt that method really slow? (no backing on that statement)
tried it, although I have group by in there for something else.
__________________
Wax on, Wax off
Orc is offline  
Reply With Quote
Old 07-30-2008, 08:33 PM   #7 (permalink)
The Frequenter
 
Join Date: Dec 2007
Location: In my basement
Posts: 378
Thanks: 45
Aaron is on a distinguished road
Default

Then our SQL knowledge fails.
__________________
Signatures are nothing but incriminating.
Send a message via MSN to Aaron
Aaron is offline  
Reply With Quote
Old 07-31-2008, 12:50 AM   #8 (permalink)
The Acquainted
 
CoryMathews's Avatar
 
Join Date: Nov 2007
Location: USA
Posts: 194
Thanks: 7
CoryMathews is on a distinguished road
Default

Can you post the Query? or there isnt much else we can do.
CoryMathews is offline  
Reply With Quote
Old 07-31-2008, 11:28 AM   #9 (permalink)
Orc
The Prestige
 
Orc's Avatar
 
Join Date: Dec 2007
Location: On your Hard Drive, hiding like a Virus
Posts: 888
Thanks: 168
Orc is on a distinguished road
Default

sql Code:
SELECT
            t.tid,
            t.title AS thread_title,
            t.created,
            t.mid,
            t.fid,
            f.title AS forum_title,
            f.DESC  AS forum_desc,
            f.created AS forum_timestamp,
            fc.title AS fc_title,
            m.username AS member_username,
            m.mid AS member_uid,
            p.created AS post_time,
            p.msg AS post_msg,
            m.signature AS member_signature,
            p.pid,
            r.rid,
            COUNT(DISTINCT r.rid) AS rating_count
            FROM `threads` AS t
           
            LEFT JOIN `posts` AS p ON p.tid=t.tid
            LEFT JOIN `forums` AS f ON f.fid=t.fid
            LEFT JOIN `forum_categories` AS fc ON f.catid=fc.fcid
            LEFT JOIN `members` AS m ON m.mid=p.mid
            LEFT JOIN `member_ratings` AS r ON r.pid=p.pid
           
           
       
           
           
            WHERE t.tid = '".$tid."'
            AND   f.fid = '".$fid."'
           
            GROUP BY p.pid
            ORDER BY p.pid

I only get 1 row from member_ratings
__________________
Wax on, Wax off
Orc is offline  
Reply With Quote
Old 07-31-2008, 01:59 PM   #10 (permalink)
The Acquainted
 
CoryMathews's Avatar
 
Join Date: Nov 2007
Location: USA
Posts: 194
Thanks: 7
CoryMathews is on a distinguished road
Default

wow thats a hell of a query. Are you sure there even is more then 1 row that should be returned? you have quite a bit of restrictions on that. Also it might be better to break that into more then 1 query, I bet that runs hella slow im gonna guess at least 10 seconds, if the tables have some sort of data in them.
CoryMathews is offline  
Reply With Quote
Old 07-31-2008, 02:03 PM   #11 (permalink)
Orc
The Prestige
 
Orc's Avatar
 
Join Date: Dec 2007
Location: On your Hard Drive, hiding like a Virus
Posts: 888
Thanks: 168
Orc is on a distinguished road
Default

Tried multiple queries, didn't work, and I didn't like the idea in the first place.

By the way, it takes me 1 second. with a cache at least..

With cleared cache, it took 2 seconds. :P
__________________
Wax on, Wax off
Orc is offline  
Reply With Quote
Old 07-31-2008, 02:09 PM   #12 (permalink)
Orc
The Prestige
 
Orc's Avatar
 
Join Date: Dec 2007
Location: On your Hard Drive, hiding like a Virus
Posts: 888
Thanks: 168
Orc is on a distinguished road
Default

Should I reconstruct my code to work with a multiple query? Cause that's what it is, or at least I believe it 100% :P
__________________
Wax on, Wax off
Orc is offline  
Reply With Quote
Old 07-31-2008, 02:38 PM   #13 (permalink)
Orc
The Prestige
 
Orc's Avatar
 
Join Date: Dec 2007
Location: On your Hard Drive, hiding like a Virus
Posts: 888
Thanks: 168
Orc is on a distinguished road
Default

Nevermind, I DID reconstruct the queries and code, and I now have it where theres two queries for the post data and then for the ratings for the post data, inner while loops :p
__________________
Wax on, Wax off
Orc is offline  
Reply With Quote
Old 07-31-2008, 03:05 PM   #14 (permalink)
The Frequenter
 
Join Date: Dec 2007
Location: In my basement
Posts: 378
Thanks: 45
Aaron is on a distinguished road
Default

So is this solved?

Also, is it better to force the browser to cache your page, or cache it on the server, or both? O.o
__________________
Signatures are nothing but incriminating.
Send a message via MSN to Aaron
Aaron is offline  
Reply With Quote
Old 08-02-2008, 07:58 AM   #15 (permalink)
Orc
The Prestige
 
Orc's Avatar
 
Join Date: Dec 2007
Location: On your Hard Drive, hiding like a Virus
Posts: 888
Thanks: 168
Orc is on a distinguished road
Default

Quote:
Originally Posted by Aaron View Post
So is this solved?

Also, is it better to force the browser to cache your page, or cache it on the server, or both? O.o
cache on server I believe.
__________________
Wax on, Wax off
Orc is offline  
Reply With Quote
Reply



Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


All times are GMT. The time now is 01:29 PM.

 
     

Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.1.0