2tonejoe Posted February 25, 2008 Share Posted February 25, 2008 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()); Quote Link to comment Share on other sites More sharing options...
fenway Posted February 25, 2008 Share Posted February 25, 2008 FULLTEXT index? Quote Link to comment Share on other sites More sharing options...
2tonejoe Posted February 25, 2008 Author Share Posted February 25, 2008 lost me on that one. Quote Link to comment Share on other sites More sharing options...
fenway Posted February 25, 2008 Share Posted February 25, 2008 Check this refman page. Quote Link to comment Share on other sites More sharing options...
2tonejoe Posted February 26, 2008 Author Share Posted February 26, 2008 i am still lost on how to implement this Quote Link to comment Share on other sites More sharing options...
fenway Posted February 26, 2008 Share Posted February 26, 2008 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? Quote Link to comment Share on other sites More sharing options...
aschk Posted February 26, 2008 Share Posted February 26, 2008 You need to dynamically build your query string (it's the only option...) e.g. if(isset($account)){ $WHERE .= "AND account_number='{$account}' "; } Quote Link to comment Share on other sites More sharing options...
fenway Posted February 26, 2008 Share Posted February 26, 2008 Even better, push onto an array, and join with AND (wrapped in parens of course). Quote Link to comment Share on other sites More sharing options...
aschk Posted February 26, 2008 Share Posted February 26, 2008 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); Quote Link to comment Share on other sites More sharing options...
fenway Posted February 26, 2008 Share Posted February 26, 2008 I like to do this: $sql = "SELECT blah FROM <table name here> WHERE ( ".implode(" ) AND ( ", $WHERE )." )"; In case there are any ORs hiding inside. Quote Link to comment Share on other sites More sharing options...
2tonejoe Posted February 26, 2008 Author Share Posted February 26, 2008 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"; } ??? Quote Link to comment Share on other sites More sharing options...
fenway Posted February 26, 2008 Share Posted February 26, 2008 That's a PHP issue... with POST and isset(). Quote Link to comment Share on other sites More sharing options...
aschk Posted February 27, 2008 Share Posted February 27, 2008 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. Quote Link to comment Share on other sites More sharing options...
fenway Posted February 27, 2008 Share Posted February 27, 2008 Just like exists vs defined in perl.. interesting. Quote Link to comment 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.