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
https://forums.phpfreaks.com/topic/77582-painted-into-a-corner-please-help/
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) //..........
?>

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.