memphisweb Posted November 16, 2007 Share Posted November 16, 2007 I'm working on an odddball solution to a funky problem At this point, the search does not include company - am trying to make it work so that the form will display properly search results with the following restrictions : company, campaign, ad width, ad height also should be able to do an any search (variable value will be "0" - any other value restricts the search I',m a little addled at the moment all are qualifiers to the search -- just having a bugger of a time writing the correct mysql -I need to figure how to dynamically calculate the sql to include the AND as well as open it up when 0 value --- please help Here is a sample string being used to build the mysql query if ( $width > 0 ) { $sqlwidth="px=$width"; } if ( $height > 0 ) { $sqlheight="py=$height AND"; } if ( $campaign > 0 ) { $sqlcampaign="campaign_id=$campaign AND"; } if ( $company > 0 ) { $sqlcompany="company_id=$ccompany AND"; } query = "SELECT file_set.* FROM file_set WHERE $sqlwidth $sqlheight $sqlcampaign "; I see where I've painted myself into a corner - not sure how to get out Quote Link to comment https://forums.phpfreaks.com/topic/77582-painted-into-a-corner-please-help/ Share on other sites More sharing options...
kopytko Posted November 16, 2007 Share Posted November 16, 2007 You could do this: <?php if ( $width > 0 ) { $sqlwidth="AND px=".$width; } if ( $height > 0 ) { $sqlheight="AND py=".$height; } if ( $campaign > 0 ) { $sqlcampaign="AND campaign_id=".$campaign; } if ( $company > 0 ) { $sqlcompany="AND company_id=".$ccompany; } query = "SELECT file_set.* FROM file_set WHERE 1 = 1 ".$sqlwidth.$sqlheight.$sqlcampaign; ?> And remeber. Check your variables. If $width an other variables must be numeric use is_numeric() function. Like this: <?php if(is_numeric($width) && $width > 0) //.......... ?> Quote Link to comment https://forums.phpfreaks.com/topic/77582-painted-into-a-corner-please-help/#findComment-392732 Share on other sites More sharing options...
fenway Posted November 19, 2007 Share Posted November 19, 2007 I'll make my usual suggestion of building an array. Quote Link to comment https://forums.phpfreaks.com/topic/77582-painted-into-a-corner-please-help/#findComment-394450 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.