Mysidia Adoptables Support Forum  

Home Community Mys-Script Creative Off-Topic
Go Back   Mysidia Adoptables Support Forum > Mysidia Adoptables > Questions and Supports

Notices

Reply
 
Thread Tools Display Modes
  #1  
Old 04-05-2010, 02:23 AM
Arianna's Avatar
Arianna Arianna is offline
Dev Staff
 
Join Date: Sep 2009
Posts: 334
Gender: Female
Credits: 21,310
Arianna will become famous soon enough
Arrow Join query for optimization?

I'm trying to make so siggy.php (function getcurrentimage($id)) uses one join query.
Now, this query has been tweaked and tweaked and tweaked, but it gets too many rows from the db. My original query worked fine if it wasn't an egg, but if it was (level=0) then it selected nothing at all.
PHP Code:
SELECT *                                                                       // easy, it just selects
FROM adopts_adoptablesadopts_owned_adoptablesadopts_levels                // where it selects from
WHERE  `adopts_owned_adoptables`.`aid` = 144 AND                              // where the adoptable id is the one we want
`adopts_owned_adoptables`.`type` = `adopts_adoptables`.`type` AND             // where the adopts type is the type we select from adopts_adoptables
(`adopts_levels`.`adoptiename` = `adopts_adoptables`.`type` OR                // either    (a) the level's type name is equal to the adopt's type
`adopts_owned_adoptables`.`currentlevel` = 0) AND                            // or        (b) the adopt's current level is equal to 0
(`adopts_owned_adoptables`.`currentlevel` = `adopts_levels`.`thisislevel`    // and either    (a) the adopt's current level is the level we select from the db
 
OR `adopts_owned_adoptables`.`currentlevel` = 0)                            // or            (b) the adopt's current level is equal to 0
LIMIT 1                                                                        // we only want one adoptable 
Any idea on what I should do? I want to use a join query as these images are used so much, but it's so complicated. :P
Reply With Quote
  #2  
Old 04-08-2010, 09:56 PM
Seapyramid Seapyramid is offline
Premium Member
 
Join Date: Feb 2009
Posts: 373
Gender: Female
Credits: 15,587
Seapyramid
Default RE: Join query for optimization?

The query is wrong. You are selecting from multiple tables.. but not telling it what to look for in what table.
FROM ".$prefix."owned_adoptables AS a JOIN
PHP Code:
SELECT *                                                                       
FROM adopts_adoptables AS a JOIN adopts_owned_adoptables AS b ON  a.aid=b.aid 
JOIN adopts_levels  
AS c ON a.aid=c.aid           
WHERE  
`a.aid` = 144 AND                            
`
a.type` = `adopts_adoptables`.`type` AND          
(`
adopts_levels`.`adoptiename` = `adopts_adoptables`.`type` OR                
`
adopts_owned_adoptables`.`currentlevel` = 0) AND                       
(`
adopts_owned_adoptables`.`currentlevel` = `adopts_levels`.`thisislevel`
 OR `
adopts_owned_adoptables`.`currentlevel` = 0)                            
LIMIT 1 
This isn't fully complete.. but you can see my changes & work with the pattern on what the WHERE is.

Sea
Reply With Quote
  #3  
Old 04-09-2010, 12:32 PM
Arianna's Avatar
Arianna Arianna is offline
Dev Staff
 
Join Date: Sep 2009
Posts: 334
Gender: Female
Credits: 21,310
Arianna will become famous soon enough
Default RE: Join query for optimization?

Thank you! :) I had gotten around it by adding a level 0 for each adoptable, but this will do much better. x3
Reply With Quote
Reply


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

Similar Threads
Thread Thread Starter Forum Replies Last Post
Database Query: COUNT(*) Kyttias Questions and Supports 5 01-19-2015 03:57 AM
CSS Query .-. ChibiMaestro Templates and Themes 2 12-08-2012 05:51 AM
Delete query deletes from all usesrs SilverDragonTears Questions and Supports 8 05-14-2012 07:49 PM
Having a problem running a query !Alive Questions and Supports 8 03-11-2012 02:39 PM
MySQL Query Empty on default install? (i.e. No edits.) Flametail Questions and Supports 3 10-18-2011 12:30 PM


All times are GMT -5. The time now is 01:56 PM.

Currently Active Users: 9746 (0 members and 9746 guests)
Threads: 4,080, Posts: 32,024, Members: 2,016
Welcome to our newest members, jolob.
BETA





What's New?

What's Hot?

What's Popular?


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2024, vBulletin Solutions Inc.
vBCommerce I v2.0.0 Gold ©2010, PixelFX Studios
vBCredits I v2.0.0 Gold ©2010, PixelFX Studios
Emoticons by darkmoon3636