If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Database Server Software > MySQL > Painted into a corner?

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 12-18-10, 13:27
oldnickj oldnickj is offline
Registered User
 
Join Date: Jan 2009
Posts: 103
Painted into a corner?

I the following query, which works quite well. I either select everything, when colname='rand' or the results of filtering drop down boxes. You can see it in action at: https://www.artcardsforcauses.com/gallery.php?thm=rand . What I would like it to have this initial view, when no filtering is selected, to be a random selection of art work from the last 90 days.

SELECT *
, country_art
FROM image_img
LEFT JOIN label
ON id_lbl=(theme_img
OR style_img
OR medium_img
OR season_img)
LEFT JOIN artist_art On artist_img=user_art
WHERE approvedIMG=1
AND private_img <> 1
OR `private_img`IS NULL
AND (colname LIKE 'rand')
OR( artist_img = colname2
AND theme_img LIKE %colname3%
AND medium_img LIKE %colname4%
AND style_img LIKE %colname5%
AND season_img LIKE %colname6%
AND country_art LIKE %colname7%)
ORDER BY cdates_img DESC

(I hope this formatting works for Rudy!)

Nick
Reply With Quote
  #2 (permalink)  
Old 12-18-10, 13:57
r937 r937 is online now
SQL Consultant
 
Join Date: Apr 2002
Location: Toronto, Canada
Posts: 19,534
Quote:
Originally Posted by oldnickj View Post
(I hope this formatting works for Rudy!)
nope, it didn't

before i look at a query, i have to understand where the columns are coming from

could you please revise it, and supply the missing table qualifiers
Code:
SELECT _____.something
     , _____.anything
     , _____.just_not_the_dreaded_evil_select_star 
     , _____.country_art
  FROM image_img 
LEFT OUTER
  JOIN label 
    ON _____.id_lbl = ( _____.theme_img 
                     OR _____.style_img 
                     OR _____.medium_img 
                     OR _____.season_img ) 
LEFT OUTER
  JOIN artist_art 
    On _____.artist_img = _____.user_art
 WHERE _____.approvedIMG = 1 
   AND _____.private_img <> 1 
    OR _____.`private_img`IS NULL 
   AND ( _____.colname LIKE 'rand' ) 
    OR ( _____.artist_img = _____.colname2 
     AND _____.theme_img LIKE %colname3% 
     AND _____.medium_img LIKE %colname4% 
     AND _____.style_img LIKE %colname5% 
     AND _____.season_img LIKE %colname6% 
     AND _____.country_art LIKE %colname7% )
ORDER 
    BY _____.cdates_img DESC
also, just looking at your mix of ANDs and ORs in the WHERE clause, i'm pretty sure i know what you wanted it to mean, but i can assure you that it doesn't actually work the way you wanted

also, looking at your first ON clause, it is for sure not executing the way you think

i dispute your claim that this query "works quite well"

no offence

__________________
r937.com | rudy.ca
please visit Simply SQL and buy my book
Reply With Quote
  #3 (permalink)  
Old 12-18-10, 15:59
oldnickj oldnickj is offline
Registered User
 
Join Date: Jan 2009
Posts: 103
right!

The variables are record ids from a lookup table. (attached)

SELECT image_img.id_img, artist_art.country
FROM image_img
LEFT OUTER
JOIN label
ON label.id_lbl = ( $theme_img
OR $style_img
OR $medium_img
OR $season_img )
LEFT OUTER
JOIN artist_art
On image_img.artist_img = artist_art.user_art
WHERE image_img.approvedIMG = 1
AND image_img.private_img <> 1
OR image_img.`private_img`IS NULL
AND ( $URLvar LIKE 'rand' )
OR ( image_img.artist_img = $artist
AND image_img.theme_img LIKE %$theme%
AND image_img.medium_img LIKE %$medium%
AND image_img.style_img LIKE %$style%
AND image_img.season_img LIKE %$season%
AND image_img.country_art LIKE %$country% )
ORDER
BY imageimg.cdates_img DESC
Attached Files
File Type: zip ac4c_nick_label.sql.zip (1.8 KB, 3 views)
Reply With Quote
  #4 (permalink)  
Old 12-18-10, 16:12
oldnickj oldnickj is offline
Registered User
 
Join Date: Jan 2009
Posts: 103
Your right it is not working perfectly, the more testing I do the more problems I have. Time is short today but I will follow up on your pointers.

Thank you
Reply With Quote
  #5 (permalink)  
Old 12-19-10, 13:26
oldnickj oldnickj is offline
Registered User
 
Join Date: Jan 2009
Posts: 103
Ultimately I convinced my wife that even when this works the result is not so desirable. Until she have images in every combination the viewer will see empty results most of the time.

So back to square one

Nick
Reply With Quote
Reply

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

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