Jump to content

painted into a corner, please help


memphisweb

Recommended Posts

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

Link to comment
Share on other sites

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) //..........
?>

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.