savagenoob Posted July 4, 2010 Share Posted July 4, 2010 I have 1 table that I want to do a search on, with 3 variables. Whats the easiest way to do this, I want to search by either/or. <?php session_start(); $agency = $_SESSION['SESS_AGENCY']; $agent = $_SESSION['SESS_MEMBER_ID']; $firstname = $_GET['First_Name']; $lastname = $_GET['Last_Name']; $polnum = $_GET['PolNum']; $date1 = $_GET['Date1']; $date2 = $_GET['Date2']; $date1 = strtotime($date1); $date2 = strtotime($date2); $newdate1= date('Y-m-d', $date1); $newdate2= date('Y-m-d', $date2); $time2 = " 00:00:01"; $time = " 23:59:59"; $date3 = $newdate2 . $time; $date4 = $newdate1 . $time2; $daterange = $_REQUEST['daterange']; require_once('../config.php'); //Array to store validation errors $errmsg_arr = array(); //Validation error flag $errflag = false; //Connect to mysql server $link = mysql_connect(DB_HOST, DB_USER, DB_PASSWORD); if(!$link) { die('Failed to connect to server: ' . mysql_error()); } //Select database $db = mysql_select_db(DB_DATABASE); if(!$db) { die("Unable to select database"); } if($daterange = "today"){ $todaytime1 = " 00:00:01"; $todaytime2 = " 23:59:59"; $datetoday = date('Y-m-d'); $todaydate1 = $datetoday . $todaytime1; $todaydate2 = $datetoday . $todaytime2; $todayquery = mysql_query("SELECT * FROM clients WHERE First_Name = '%". $firstname ."%' AND Last_Name = '%". $lastname ."%' AND Agency = '$agency' BETWEEN '$todaydate1' AND '$todaydate2' ") or die(mysql_error()); $numrows = mysql_num_rows($todayquery); if($numrows == 0){ echo "No prospects matching that criteria."; }?> This will only return a restult if all 3 return somthing..... Link to comment https://forums.phpfreaks.com/topic/206676-php-mysql-search/ Share on other sites More sharing options...
fenway Posted July 6, 2010 Share Posted July 6, 2010 You need LIKE, not = Link to comment https://forums.phpfreaks.com/topic/206676-php-mysql-search/#findComment-1081853 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.