Jump to content

Multiple HTML Fields that a user can use, but doesn't have to . . . how do I q..


2tonejoe

Recommended Posts

How do I query on that. They have 7 text inputs that they can enter text into, but they don't have to enter text into each one. I need to query a database on the possible text that they enter. How can I do this? If I leave it as, and someone doesn't type something in one of the fields . . . i am hosed. it returns nothing. Do I have to make a query for each individual possible combination . . ?

 

my query as it stands:

$result = mysql_query("SELECT  `page_number` ,  `ad_name` ,  `book_issue` ,  `io_barcode` ,  `account_number` ,  `book_code` ,  `book_version` ,  `book_type` ,  `clock`  FROM  `ad_info`  WHERE  `book_year` ='$year' AND `book_issue` ='$issue' AND `book_code` ='$bookCode' AND `book_type` ='$bookSection' AND `io_barcode` ='$ioBarcode' AND `ad_name` ='$adName' AND `account_number` ='$account' ORDER BY `page_number` ASC") or die(mysql_error());  

I'm confused about your original question, then -- is the problem that you only want to query the particular search fields that are non-blank, or that the info could be in any of a number of fields?

Ooh yeah nice:

 

if(isset($account)){
  $WHERE[] = "account_number = '$account'";
}
if(isset($adName)){
  $WHERE[] = "ad_name = '$adName'";
}

// then

$sql = "SELECT blah FROM <table name here> WHERE ".implode(" AND ", $WHERE);

great. now my issue is that the variables are set. the come across as like

$account = $_POST['account'];

they are printing "yes" in the following statement even if they don't have anything. . .

if(isset($account)){
$WHERE[] = "ad_info.account_number = '$account'";
echo "yes";
}

 

???

Ah yes,

 

i see the problem. You've created a variable (called $account) and assigned it whatever value is held in $_POST['account'], HOWEVER the index "account" in the POST does NOT exist, however your variable $account is still created, and thus IS set. Use empty() instead.

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.