Go Back   CodingForums.com > :: Server side development > PHP

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 11-05-2012, 07:49 PM   PM User | #1
amie
New to the CF scene

 
Join Date: Jul 2012
Posts: 7
Thanks: 0
Thanked 0 Times in 0 Posts
amie is an unknown quantity at this point
MySQL Table Results to Process Another Table Results

Below you will find my code, it's not it all in it's entirety, but shows what's important. I have some custom functions that are being used just to note out. What I have my code doing is searching a MySQL table and displaying all of the results based on the current session user id. Then I loop through those results and for each one I search another table. This works perfectly, but I just want to see if there is a better way to do this without having to loop and search a table for every result row.

Code: http://pastie.org/5191376
amie is offline   Reply With Quote
Old 11-05-2012, 07:58 PM   PM User | #2
Fou-Lu
God Emperor


 
Fou-Lu's Avatar
 
Join Date: Sep 2002
Location: Saskatoon, Saskatchewan
Posts: 15,752
Thanks: 4
Thanked 2,468 Times in 2,437 Posts
Fou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to all
Never query in a loop. That stacks (potentially) hundreds of queries for a single run.
Join it.
PHP Code:
$sQry "SELECT p.shop_id, p.distributor_id, q.id, q.service, q.start_date, q.end_date
FROM participation p
INNER JOIN qpons q ON q.id = p.qpon_id
WHERE p.shop_id = '{$session->user_id}'"

Loop it and go. You'll need to set up any ordering and use PHP to do some magic if you need to change the visual layout (all the qpons per shop_id, distributor_id, etc).
Fou-Lu is offline   Reply With Quote
Old 11-06-2012, 12:17 AM   PM User | #3
amie
New to the CF scene

 
Join Date: Jul 2012
Posts: 7
Thanks: 0
Thanked 0 Times in 0 Posts
amie is an unknown quantity at this point
Looks like it would work but it then returns this:

Database query failed: Illegal mix of collations (utf8_unicode_ci,IMPLICIT) and (utf8_general_ci,IMPLICIT) for operation '='
amie is offline   Reply With Quote
Old 11-06-2012, 01:52 PM   PM User | #4
Fou-Lu
God Emperor


 
Fou-Lu's Avatar
 
Join Date: Sep 2002
Location: Saskatoon, Saskatchewan
Posts: 15,752
Thanks: 4
Thanked 2,468 Times in 2,437 Posts
Fou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to all
Either change the database so it matches the collation across the board, or try to issue the COLLATE() SQL function to force it to match on the ON clause. I'd suggest modifying the db to match the collation and then adding a foreign key constraint assuming you have an innodb engine type and are using mysql.
Fou-Lu is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

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

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 12:12 PM.


Advertisement
Log in to turn off these ads.