svgmx5 Posted December 18, 2009 Share Posted December 18, 2009 Hey everyone, i hope someone here can help me out with this small issue i have. Currently i have a script that does a search query on my DB,i want it to search for three things, a starting date, an ending date and the state. Currently its only working if i search for a date and a state, but if i try to search for the startind date and endind date i get no results. So what i'm trying to figure out is how to make it search for the starting date and ending date. Currently on my database i have the id, name, city, state and date fields . the date field is filled out as follow: YYYY/MM/DD And this is the script that does the query: if (isset($_GET['currentpage']) && is_numeric($_GET['currentpage'])) { // cast var as int $currentpage = (int) $_GET['currentpage']; } else { // default page num $currentpage = 1; } // end if $date = $_GET['fromDate']; $state = $_GET['state']; $rowsperpage = 30; $offset = ($currentpage - 1) * $rowsperpage; //retrieve the info from DB $sql = "SELECT COUNT(*) FROM leads WHERE date = '$date' && state = '$state'"; $result = mysql_query($sql) or trigger_error("SQL", E_USER_ERROR); $r = mysql_fetch_row($result); $numrows = $r[0]; $totalpages = ceil($numrows / $rowsperpage); $sql = "SELECT * FROM leads WHERE date = '$date' && state = '$state' LIMIT $rowsperpage OFFSET $offset"; $result = mysql_query($sql) or die("Problem, with Query:".mysql_error()); $num = 0; Finally here is my form were i input the fields: <form method="get" action="results.php"> <table width="800" align="right" cellpadding="0" cellspacing="5"> <tr> <td width="233"><p>Date From: <input type="text" name="fromDate" /> </p></td> <td width="196"><p> </p></td> <td width="234"><p>State: <input type="text" name="state" /> </p></td> <td width="110"> <input type="hidden" name="searching" value='yes'/> <input name="search2" type="submit" id="search2" value="Search" /> </td> </tr> </table> </form> I hope someone can help me out wit this issue Thanks in advanced! Link to comment https://forums.phpfreaks.com/topic/185614-searching-mysql-database-using-php/ Share on other sites More sharing options...
emopoops Posted December 18, 2009 Share Posted December 18, 2009 ur mysql thing doesnt make any sense why use count if ur having two seperate nyusql queryes. unbelievebale Link to comment https://forums.phpfreaks.com/topic/185614-searching-mysql-database-using-php/#findComment-979984 Share on other sites More sharing options...
svgmx5 Posted December 18, 2009 Author Share Posted December 18, 2009 ok... So what do you suggest i should do then? Actually i was using count to count the number of items that are being retrieve from the DB Link to comment https://forums.phpfreaks.com/topic/185614-searching-mysql-database-using-php/#findComment-979987 Share on other sites More sharing options...
emopoops Posted December 18, 2009 Share Posted December 18, 2009 if urusing count make it of the original query that is being used. Link to comment https://forums.phpfreaks.com/topic/185614-searching-mysql-database-using-php/#findComment-979991 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.