downah Posted April 4, 2012 Share Posted April 4, 2012 Hey guys, at the moment I am trying to do an advanced search on events, 4 fields - county, date, title and hoster, so I am not really sure how to go about this but either way I started writing a script to do this, you learn from trying and mistaken right? Now I made sure the radio buttons all worked before I tryed this, checking the values of them on the form (seperate page) and if they get transferred correctly over to this page, basically for every field there are 2 radio boxes yes and No, which means for them to be included in the search or not, this is the code I have so far and if no radio buttons are selected and the fields are empty it comes up with the table and no results, when everything is set to no the page is blank, when everything is set to yes and I put the correct information in the fields then it comes up with the right data, so far it basically only works if all is yes (I will change it to LIKE later so they don't have to put in the exact information for certain fields) so I guess I am on the right way? Where and what am I doing wrong? <?php session_start(); include 'connect.php'; $username = $_SESSION['username']; if(!isset($_SESSION['username'])) { echo '<div align="center">'; echo 'You have to be a registered member to be able to view events.<br><br> <a href="register.html">Click here to register</a>'; echo '<br><br><br><br>Or if you are already a member, please login to use this area.<br>'; echo ' <form method="POST" action="loginverification.php"> <table border="0"> <tr><td> Username: </td><td><input type="text" name="username" size="15" /></td></tr> <tr><td>Password:</td><td> <input type="password" name="password" size="15" /></td></tr> </table> <div align="center"> <p><input type="submit" value="Login" /></p> </div> </form>'; echo '</div>'; } else{ $theDate = isset($_REQUEST["date1"]) ? $_REQUEST["date1"] : ""; $eventcounty = $_POST['county']; $eventdescriptionheader = $_POST['eventdescriptionheader']; $hoster = $_POST['hoster']; if($_POST['searchcounty'] == "No") { $result = mysql_query("SELECT * FROM Events WHERE eventdate = '$theDate' AND eventdescriptionheader = '$eventdescriptionheader' AND hoster = '$hoster' ORDER BY eventdate ASC")or die(mysql_error()); } elseif($_POST['searchdate'] == "No") { $result = mysql_query("SELECT * FROM Events WHERE eventcounty = '$eventcounty' AND eventdescriptionheader = '$eventdescriptionheader' AND hoster = '$hoster' ORDER BY eventdate ASC")or die(mysql_error()); } elseif($_POST['searchtitle'] == "No") { $result = mysql_query("SELECT * FROM Events WHERE eventcounty = '$eventcounty' AND eventdate = '$theDate' AND hoster = '$hoster' ORDER BY eventdate ASC")or die(mysql_error()); } elseif($_POST['searchhoster'] == "No") { $result = mysql_query("SELECT * FROM Events WHERE eventcounty = '$eventcounty' AND eventdate = '$theDate' AND eventdescriptionheader = '$eventdescriptionheader' ORDER BY eventdate ASC")or die(mysql_error()); } else { $result = mysql_query("SELECT * FROM Events WHERE eventcounty = '$eventcounty' AND eventdate = '$theDate' AND hoster = '$hoster' AND eventdescriptionheader = '$eventdescriptionheader' ORDER BY eventdate ASC")or die(mysql_error()); echo '<br>'; echo "<table border='0'> <tr> <th>Date/Time</th> <th>Event</th> <th>Participants</th> <th>Hoster</th> </tr>"; while($row = mysql_fetch_array($result)) { echo "<tr>"; echo "<td>"; print date('d M Y', strtotime($row['eventdate'])); echo " "; echo $row['starttime'] . "</td>"; echo '<td><a href="showevent.php?eventsID='; echo $row['eventsID']; echo '">'; echo $row['eventdescriptionheader']; echo "</a></td>"; echo "<td>" . $row['currentparticipants'] . "/" . $row['maxparticipants'] . "</td>"; echo "<td>" . $row['hoster'] . "</td>"; echo "</tr>"; } echo '</table>'; $check = mysql_num_rows($result); if ($theDate == "0000-00-00") { echo 'You did not select a date.'; echo '<INPUT TYPE="button" VALUE="Back" onClick="history.go(-1);return true;">'; } elseif ($check == 0) { echo 'No results found.'; echo '<INPUT TYPE="button" VALUE="Back" onClick="history.go(-1);return true;">'; } echo '<br><INPUT TYPE="button" VALUE="Back" onClick="history.go(-1);return true;"> '; } } ?> Quote Link to comment https://forums.phpfreaks.com/topic/260364-advanced-search/ Share on other sites More sharing options...
samshel Posted April 4, 2012 Share Posted April 4, 2012 I am not sure if i understand correctly but will still give a try Are you looking for something like this? Code is not tested so you may have to fix some syntax errors <?php session_start(); include 'connect.php'; $username = $_SESSION['username']; if(!isset($_SESSION['username'])) { echo '<div align="center">'; echo 'You have to be a registered member to be able to view events.<br><br> <a href="register.html">Click here to register</a>'; echo '<br><br><br><br>Or if you are already a member, please login to use this area.<br>'; echo ' <form method="POST" action="loginverification.php"> <table border="0"> <tr><td> Username: </td><td><input type="text" name="username" size="15" /></td></tr> <tr><td>Password:</td><td> <input type="password" name="password" size="15" /></td></tr> </table> <div align="center"> <p><input type="submit" value="Login" /></p> </div> </form>'; echo '</div>'; } else{ $theDate = isset($_REQUEST["date1"]) ? $_REQUEST["date1"] : ""; $eventcounty = $_POST['county']; $eventdescriptionheader = $_POST['eventdescriptionheader']; $hoster = $_POST['hoster']; $arrWhere = array(); if($_POST['searchcounty'] == "Yes") { $arrWhere['eventcounty'] = mysql_real_escape_string($eventcounty); } if($_POST['searchdate'] == "Yes") { $arrWhere['eventdate'] = mysql_real_escape_string($theDate); } if($_POST['searchtitle'] == "Yes") { $arrWhere['eventdescriptionheader'] = mysql_real_escape_string($eventdescriptionheader); } if($_POST['searchhoster'] == "Yes") { $arrWhere['hoster'] = mysql_real_escape_string($hoster); } $strWhere = 'WHERE '; if(count($arrWhere)){ foreach($arrWhere as $strKey=>$strValue){ $strWhere .= ' '.$strKey.' = '.'"'.$strValue.'" AND '; } $strWhere .= ' 1 '; } else { $strWhere = ' 1'; // if you want all records to be selected if no radio is checked. if you want no records make this as '0' } $strSql = "SELECT * FROM Events $strWhere ORDER BY eventdate ASC" $result = mysql_query($strSql); echo '<br>'; echo "<table border='0'> <tr> <th>Date/Time</th> <th>Event</th> <th>Participants</th> <th>Hoster</th> </tr>"; while($row = mysql_fetch_array($result)) { echo "<tr>"; echo "<td>"; print date('d M Y', strtotime($row['eventdate'])); echo " "; echo $row['starttime'] . "</td>"; echo '<td><a href="showevent.php?eventsID='; echo $row['eventsID']; echo '">'; echo $row['eventdescriptionheader']; echo "</a></td>"; echo "<td>" . $row['currentparticipants'] . "/" . $row['maxparticipants'] . "</td>"; echo "<td>" . $row['hoster'] . "</td>"; echo "</tr>"; } echo '</table>'; $check = mysql_num_rows($result); if ($theDate == "0000-00-00") { echo 'You did not select a date.'; echo '<INPUT TYPE="button" VALUE="Back" onClick="history.go(-1);return true;">'; } elseif ($check == 0) { echo 'No results found.'; echo '<INPUT TYPE="button" VALUE="Back" onClick="history.go(-1);return true;">'; } echo '<br><INPUT TYPE="button" VALUE="Back" onClick="history.go(-1);return true;"> '; } ?> Quote Link to comment https://forums.phpfreaks.com/topic/260364-advanced-search/#findComment-1334481 Share on other sites More sharing options...
downah Posted April 4, 2012 Author Share Posted April 4, 2012 Couple of tiny errors in there but got it working great! absolutely awesome thanks a lot, I really need to get my head around these arrays, I do understand your code when I read it slowly but writing that is still pretty advanced! Quote Link to comment https://forums.phpfreaks.com/topic/260364-advanced-search/#findComment-1334490 Share on other sites More sharing options...
downah Posted April 4, 2012 Author Share Posted April 4, 2012 Any idea on how I could incorporate any? <?php if($_POST['couplesonly'] == "Any") { $dogfriendly = "*"; $arrWhere['couplesonly'] = mysql_real_escape_string($couplesonly); } ?> Quote Link to comment https://forums.phpfreaks.com/topic/260364-advanced-search/#findComment-1334495 Share on other sites More sharing options...
downah Posted April 4, 2012 Author Share Posted April 4, 2012 Nevermind silly question, got it all working with my modifications and a lot more search fields let this topic die Quote Link to comment https://forums.phpfreaks.com/topic/260364-advanced-search/#findComment-1334497 Share on other sites More sharing options...
samshel Posted April 5, 2012 Share Posted April 5, 2012 For Any, you dont need to add anything, Any = all records so no search field to be added. Quote Link to comment https://forums.phpfreaks.com/topic/260364-advanced-search/#findComment-1334502 Share on other sites More sharing options...
downah Posted April 5, 2012 Author Share Posted April 5, 2012 I figured I send you a little PM if you don't mind! Small troubles with inserting this code within pages Quote Link to comment https://forums.phpfreaks.com/topic/260364-advanced-search/#findComment-1334503 Share on other sites More sharing options...
downah Posted April 5, 2012 Author Share Posted April 5, 2012 For anyone else who could help that would be great! Trying to insert pages, it is breaking it up right but when I click on 1 or next I get this syntax error: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '1 ORDER BY eventdate ASC' at line 1 <?php include 'connect.php'; require_once('calendar/classes/tc_calendar.php'); session_start(); if(!isset($_SESSION['username'])) { echo '<div align="center">'; echo 'You have to be a registered member to be able to view events.<br><br> <a href="register.html">Click here to register</a>'; echo '<br><br><br><br>Or if you are already a member, please login to use this area.<br>'; echo ' <form method="POST" action="loginverification.php"> <table border="0"> <tr><td> Username: </td><td><input type="text" name="username" size="15" /></td></tr> <tr><td>Password:</td><td> <input type="password" name="password" size="15" /></td></tr> </table> <div align="center"> <p><input type="submit" value="Login" /></p> </div> </form>'; echo '</div>'; } else{ $page_name="searchevents.php"; // If you use this code with a different page ( or file ) name then change this $start=$_GET['start']; if(strlen($start) > 0 and !is_numeric($start)){ echo "Data Error"; exit; } $eu = ($start - 0); $limit = 5; // No of records to be shown per page. $this1 = $eu + $limit; $back = $eu - $limit; $next = $eu + $limit; /////////////// WE have to find out the number of records in our table. We will use this to break the pages/////// $theDate = isset($_REQUEST["date1"]) ? $_REQUEST["date1"] : ""; $eventcounty = $_POST['county']; $eventdescriptionheader = $_POST['eventdescriptionheader']; $hoster = $_POST['hoster']; $arrWhere = array(); if($_POST['searchcounty'] == "yes") { $arrWhere['eventcounty'] = mysql_real_escape_string($eventcounty); } if($_POST['searchdate'] == "yes") { $arrWhere['eventdate'] = mysql_real_escape_string($theDate); } if($_POST['searchtitle'] == "yes") { $arrWhere['eventdescriptionheader'] = mysql_real_escape_string($eventdescriptionheader); } if($_POST['searchhoster'] == "yes") { $arrWhere['hoster'] = mysql_real_escape_string($hoster); } if($_POST['dogfriendly'] == "No") { $dogfriendly = $_POST['dogfriendly']; $arrWhere['dogfriendly'] = mysql_real_escape_string($dogfriendly); } if($_POST['dogfriendly'] == "Yes") { $dogfriendly = $_POST['dogfriendly']; $arrWhere['dogfriendly'] = mysql_real_escape_string($dogfriendly); } if($_POST['childfriendly'] == "No") { $childfriendly = $_POST['childfriendly']; $arrWhere['childfriendly'] = mysql_real_escape_string($childfriendly); } if($_POST['childfriendly'] == "Yes") { $childfriendly = $_POST['childfriendly']; $arrWhere['childfriendly'] = mysql_real_escape_string($childfriendly); } if($_POST['singlesonly'] == "No") { $singlesonly = $_POST['singlesonly']; $arrWhere['singlesonly'] = mysql_real_escape_string($singlesonly); } if($_POST['singlesonly'] == "Yes") { $singlesonly = $_POST['singlesonly']; $arrWhere['singlesonly'] = mysql_real_escape_string($singlesonly); } if($_POST['couplesonly'] == "No") { $couplesonly = $_POST['couplesonly']; $arrWhere['couplesonly'] = mysql_real_escape_string($couplesonly); } if($_POST['couplesonly'] == "Yes") { $couplesonly = $_POST['couplesonly']; $arrWhere['couplesonly'] = mysql_real_escape_string($couplesonly); } if($_POST['costinvolved'] == "No") { $costinvolved = $_POST['costinvolved']; $arrWhere['costinvolved'] = mysql_real_escape_string($costinvolved); } if($_POST['costinvolved'] == "Yes") { $costinvolved = $_POST['costinvolved']; $arrWhere['costinvolved'] = mysql_real_escape_string($costinvolved); } $strWhere = 'WHERE '; if(count($arrWhere)){ foreach($arrWhere as $strKey=>$strValue){ $strWhere .= ' '.$strKey.' = '.'"'.$strValue.'" AND '; } $strWhere .= ' 1 '; } else { $strWhere = ' 1'; // if you want all records to be selected if no radio is checked. if you want no records make this as '0' } $strSql = "SELECT * FROM Events $strWhere ORDER BY eventdate ASC limit $eu, $limit"; $query2="SELECT * FROM Events $strWhere ORDER BY eventdate ASC"; $result2=mysql_query($query2); echo mysql_error(); $nume=mysql_num_rows($result2); $result = mysql_query($strSql); echo '<br>'; echo "<table border='0'> <tr> <th>Date/Time</th> <th>Event</th> <th>Participants</th> <th>Hoster</th> </tr>"; while($row = mysql_fetch_array($result)) { echo "<tr>"; echo "<td>"; print date('d M Y', strtotime($row['eventdate'])); echo " "; echo $row['starttime'] . "</td>"; echo '<td><a href="showevent.php?eventsID='; echo $row['eventsID']; echo '">'; echo $row['eventdescriptionheader']; echo "</a></td>"; echo "<td>" . $row['currentparticipants'] . "/" . $row['maxparticipants'] . "</td>"; echo "<td>" . $row['hoster'] . "</td>"; echo "</tr>"; } echo '</table>'; echo '<br><br><INPUT TYPE="button" VALUE="Back" onClick="history.go(-1);return true;">'; ////////////////////////////// End of displaying the table with records //////////////////////// /////////////////////////////// if($nume > $limit ){ // Let us display bottom links if sufficient records are there for paging /////////////// Start the bottom links with Prev and next link with page numbers ///////////////// echo "<table align = 'center' width='50%'><tr><td align='left' width='30%'>"; //// if our variable $back is equal to 0 or more then only we will display the link to move back //////// if($back >=0) { print "<a href='$page_name?start=$back'>PREV</a>"; } //////////////// Let us display the page links at center. We will not display the current page as a link /////////// echo "</td><td align=center width='30%'>"; $i=0; $l=1; for($i=0;$i < $nume;$i=$i+$limit){ if($i <> $eu){ echo " <a href='$page_name?start=$i'>$l</a> "; } else { echo "$l";} /// Current page is not displayed as link and given font color red $l=$l+1; } echo "</td><td align='right' width='30%'>"; ///////////// If we are not in the last page then Next link will be displayed. Here we check that ///// if($this1 < $nume) { print "<a href='$page_name?start=$next'>NEXT</a>";} echo "</td></tr></table>"; } } ?> Quote Link to comment https://forums.phpfreaks.com/topic/260364-advanced-search/#findComment-1334506 Share on other sites More sharing options...
samshel Posted April 5, 2012 Share Posted April 5, 2012 print the query and you don't need to fire the query twice. you can use COUNT(*). Replied PM with more details. Quote Link to comment https://forums.phpfreaks.com/topic/260364-advanced-search/#findComment-1334540 Share on other sites More sharing options...
downah Posted April 5, 2012 Author Share Posted April 5, 2012 Done that still not showing results on the other pages Quote Link to comment https://forums.phpfreaks.com/topic/260364-advanced-search/#findComment-1334635 Share on other sites More sharing options...
samshel Posted April 5, 2012 Share Posted April 5, 2012 You need to pass the search parameters to the next page, may be by appending to the URL and query checking both POST and GET. Quote Link to comment https://forums.phpfreaks.com/topic/260364-advanced-search/#findComment-1334759 Share on other sites More sharing options...
downah Posted April 5, 2012 Author Share Posted April 5, 2012 This is what I have.. I am not too sure with what you mean, I am using this exact script in another page and it is working fine, it seems because of the $strWhere ? <?php session_start(); include 'connect.php'; require_once('calendar/classes/tc_calendar.php'); if(!isset($_SESSION['username'])) { echo '<div align="center">'; echo 'You have to be a registered member to be able to view events.<br><br> <a href="register.html">Click here to register</a>'; echo '<br><br><br><br>Or if you are already a member, please login to use this area.<br>'; echo ' <form method="POST" action="loginverification.php"> <table border="0"> <tr><td> Username: </td><td><input type="text" name="username" size="15" /></td></tr> <tr><td>Password:</td><td> <input type="password" name="password" size="15" /></td></tr> </table> <div align="center"> <p><input type="submit" value="Login" /></p> </div> </form>'; echo '</div>'; } else{ $page_name="searchevents.php"; // If you use this code with a different page ( or file ) name then change this $start=$_GET['start']; if(strlen($start) > 0 and !is_numeric($start)){ echo "Data Error"; exit; } $eu = ($start - 0); $limit = 20; // No of records to be shown per page. $this1 = $eu + $limit; $back = $eu - $limit; $next = $eu + $limit; /////////////// WE have to find out the number of records in our table. We will use this to break the pages/////// $theDate = isset($_REQUEST["date1"]) ? $_REQUEST["date1"] : ""; $eventcounty = $_POST['county']; $eventdescriptionheader = $_POST['eventdescriptionheader']; $hoster = $_POST['hoster']; $arrWhere = array(); if($_POST['searchcounty'] == "yes") { $arrWhere['eventcounty'] = mysql_real_escape_string($eventcounty); } if($_POST['searchdate'] == "yes") { $arrWhere['eventdate'] = mysql_real_escape_string($theDate); } if($_POST['searchtitle'] == "yes") { $arrWhere['eventdescriptionheader'] = mysql_real_escape_string($eventdescriptionheader); } if($_POST['searchhoster'] == "yes") { $arrWhere['hoster'] = mysql_real_escape_string($hoster); } if($_POST['dogfriendly'] == "No") { $dogfriendly = $_POST['dogfriendly']; $arrWhere['dogfriendly'] = mysql_real_escape_string($dogfriendly); } if($_POST['dogfriendly'] == "Yes") { $dogfriendly = $_POST['dogfriendly']; $arrWhere['dogfriendly'] = mysql_real_escape_string($dogfriendly); } if($_POST['childfriendly'] == "No") { $childfriendly = $_POST['childfriendly']; $arrWhere['childfriendly'] = mysql_real_escape_string($childfriendly); } if($_POST['childfriendly'] == "Yes") { $childfriendly = $_POST['childfriendly']; $arrWhere['childfriendly'] = mysql_real_escape_string($childfriendly); } if($_POST['singlesonly'] == "No") { $singlesonly = $_POST['singlesonly']; $arrWhere['singlesonly'] = mysql_real_escape_string($singlesonly); } if($_POST['singlesonly'] == "Yes") { $singlesonly = $_POST['singlesonly']; $arrWhere['singlesonly'] = mysql_real_escape_string($singlesonly); } if($_POST['couplesonly'] == "No") { $couplesonly = $_POST['couplesonly']; $arrWhere['couplesonly'] = mysql_real_escape_string($couplesonly); } if($_POST['couplesonly'] == "Yes") { $couplesonly = $_POST['couplesonly']; $arrWhere['couplesonly'] = mysql_real_escape_string($couplesonly); } if($_POST['costinvolved'] == "No") { $costinvolved = $_POST['costinvolved']; $arrWhere['costinvolved'] = mysql_real_escape_string($costinvolved); } if($_POST['costinvolved'] == "Yes") { $costinvolved = $_POST['costinvolved']; $arrWhere['costinvolved'] = mysql_real_escape_string($costinvolved); } $strWhere = 'WHERE '; if(count($arrWhere)){ foreach($arrWhere as $strKey=>$strValue){ $strWhere .= ' '.$strKey.' = '.'"'.$strValue.'" AND '; } $strWhere .= ' 1 '; } else { $strWhere = ' 1'; // if you want all records to be selected if no radio is checked. if you want no records make this as '0' } $strSql = "SELECT * FROM Events $strWhere ORDER BY eventdate ASC limit $eu, $limit"; $query2="SELECT count(*) as cnt FROM Events $strWhere"; $result2 = mysql_query($query2); $row = mysql_fetch_array($result2); $nume = $row['cnt']; $result = mysql_query($strSql); echo '<br>'; echo "<table border='0'> <tr> <th>Date/Time</th> <th>Event</th> <th>Participants</th> <th>Hoster</th> </tr>"; while($row = mysql_fetch_array($result)) { echo "<tr>"; echo "<td>"; print date('d M Y', strtotime($row['eventdate'])); echo " "; echo $row['starttime'] . "</td>"; echo '<td><a href="showevent.php?eventsID='; echo $row['eventsID']; echo '">'; echo $row['eventdescriptionheader']; echo "</a></td>"; echo "<td>" . $row['currentparticipants'] . "/" . $row['maxparticipants'] . "</td>"; echo "<td>" . $row['hoster'] . "</td>"; echo "</tr>"; } echo '</table>'; echo '<br><br><INPUT TYPE="button" VALUE="Back" onClick="history.go(-1);return true;">'; ////////////////////////////// End of displaying the table with records //////////////////////// /////////////////////////////// if($nume > $limit ){ // Let us display bottom links if sufficient records are there for paging /////////////// Start the bottom links with Prev and next link with page numbers ///////////////// echo "<table align = 'center' width='50%'><tr><td align='left' width='30%'>"; //// if our variable $back is equal to 0 or more then only we will display the link to move back //////// if($back >=0) { print "<a href='$page_name?start=$back'>PREV</a>"; } //////////////// Let us display the page links at center. We will not display the current page as a link /////////// echo "</td><td align=center width='30%'>"; $i=0; $l=1; for($i=0;$i < $nume;$i=$i+$limit){ if($i <> $eu){ echo " <a href='$page_name?start=$i'>$l</a> "; } else { echo "$l";} /// Current page is not displayed as link and given font color red $l=$l+1; } echo "</td><td align='right' width='30%'>"; ///////////// If we are not in the last page then Next link will be displayed. Here we check that ///// if($this1 < $nume) { print "<a href='$page_name?start=$next'>NEXT</a>";} echo "</td></tr></table>"; } } ?> Quote Link to comment https://forums.phpfreaks.com/topic/260364-advanced-search/#findComment-1334773 Share on other sites More sharing options...
samshel Posted April 5, 2012 Share Posted April 5, 2012 Not the cleanest way, but you can store the parameters in session and use them in the query. You can reset them when the form is submitted. something like this. Again not tested... <?php session_start(); include 'connect.php'; require_once('calendar/classes/tc_calendar.php'); if(!isset($_SESSION['username'])) { echo '<div align="center">'; echo 'You have to be a registered member to be able to view events.<br><br> <a href="register.html">Click here to register</a>'; echo '<br><br><br><br>Or if you are already a member, please login to use this area.<br>'; echo ' <form method="POST" action="loginverification.php"> <table border="0"> <tr><td> Username: </td><td><input type="text" name="username" size="15" /></td></tr> <tr><td>Password:</td><td> <input type="password" name="password" size="15" /></td></tr> </table> <div align="center"> <p><input type="submit" value="Login" /></p> </div> </form>'; echo '</div>'; } else{ $page_name="searchevents.php"; // If you use this code with a different page ( or file ) name then change this $start=$_GET['start']; if(strlen($start) > 0 and !is_numeric($start)){ echo "Data Error"; exit; } $arrParameters = array(); if(isset($_POST['county'])){//should ideally be the submit button on your form $_SESSION['arrParameters'] = $_POST; } $arrParameters = $_SESSION['arrParameters']; $eu = ($start - 0); $limit = 20; // No of records to be shown per page. $this1 = $eu + $limit; $back = $eu - $limit; $next = $eu + $limit; /////////////// WE have to find out the number of records in our table. We will use this to break the pages/////// $theDate = isset($_REQUEST["date1"]) ? $_REQUEST["date1"] : ""; $eventcounty = $arrParameters['county']; $eventdescriptionheader = $arrParameters['eventdescriptionheader']; $hoster = $arrParameters['hoster']; $arrWhere = array(); if($arrParameters['searchcounty'] == "yes") { $arrWhere['eventcounty'] = mysql_real_escape_string($eventcounty); } if($arrParameters['searchdate'] == "yes") { $arrWhere['eventdate'] = mysql_real_escape_string($theDate); } if($arrParameters['searchtitle'] == "yes") { $arrWhere['eventdescriptionheader'] = mysql_real_escape_string($eventdescriptionheader); } if($arrParameters['searchhoster'] == "yes") { $arrWhere['hoster'] = mysql_real_escape_string($hoster); } if($arrParameters['dogfriendly'] == "No") { $dogfriendly = $arrParameters['dogfriendly']; $arrWhere['dogfriendly'] = mysql_real_escape_string($dogfriendly); } if($arrParameters['dogfriendly'] == "Yes") { $dogfriendly = $arrParameters['dogfriendly']; $arrWhere['dogfriendly'] = mysql_real_escape_string($dogfriendly); } if($arrParameters['childfriendly'] == "No") { $childfriendly = $arrParameters['childfriendly']; $arrWhere['childfriendly'] = mysql_real_escape_string($childfriendly); } if($arrParameters['childfriendly'] == "Yes") { $childfriendly = $arrParameters['childfriendly']; $arrWhere['childfriendly'] = mysql_real_escape_string($childfriendly); } if($arrParameters['singlesonly'] == "No") { $singlesonly = $arrParameters['singlesonly']; $arrWhere['singlesonly'] = mysql_real_escape_string($singlesonly); } if($arrParameters['singlesonly'] == "Yes") { $singlesonly = $arrParameters['singlesonly']; $arrWhere['singlesonly'] = mysql_real_escape_string($singlesonly); } if($arrParameters['couplesonly'] == "No") { $couplesonly = $arrParameters['couplesonly']; $arrWhere['couplesonly'] = mysql_real_escape_string($couplesonly); } if($arrParameters['couplesonly'] == "Yes") { $couplesonly = $arrParameters['couplesonly']; $arrWhere['couplesonly'] = mysql_real_escape_string($couplesonly); } if($arrParameters['costinvolved'] == "No") { $costinvolved = $arrParameters['costinvolved']; $arrWhere['costinvolved'] = mysql_real_escape_string($costinvolved); } if($arrParameters['costinvolved'] == "Yes") { $costinvolved = $arrParameters['costinvolved']; $arrWhere['costinvolved'] = mysql_real_escape_string($costinvolved); } $strWhere = 'WHERE '; if(count($arrWhere)){ foreach($arrWhere as $strKey=>$strValue){ $strWhere .= ' '.$strKey.' = '.'"'.$strValue.'" AND '; } $strWhere .= ' 1 '; } else { $strWhere = ' 1'; // if you want all records to be selected if no radio is checked. if you want no records make this as '0' } $strSql = "SELECT * FROM Events $strWhere ORDER BY eventdate ASC limit $eu, $limit"; $query2="SELECT count(*) as cnt FROM Events $strWhere"; $result2 = mysql_query($query2); $row = mysql_fetch_array($result2); $nume = $row['cnt']; $result = mysql_query($strSql); echo '<br>'; echo "<table border='0'> <tr> <th>Date/Time</th> <th>Event</th> <th>Participants</th> <th>Hoster</th> </tr>"; while($row = mysql_fetch_array($result)) { echo "<tr>"; echo "<td>"; print date('d M Y', strtotime($row['eventdate'])); echo " "; echo $row['starttime'] . "</td>"; echo '<td><a href="showevent.php?eventsID='; echo $row['eventsID']; echo '">'; echo $row['eventdescriptionheader']; echo "</a></td>"; echo "<td>" . $row['currentparticipants'] . "/" . $row['maxparticipants'] . "</td>"; echo "<td>" . $row['hoster'] . "</td>"; echo "</tr>"; } echo '</table>'; echo '<br><br><INPUT TYPE="button" VALUE="Back" onClick="history.go(-1);return true;">'; ////////////////////////////// End of displaying the table with records //////////////////////// /////////////////////////////// if($nume > $limit ){ // Let us display bottom links if sufficient records are there for paging /////////////// Start the bottom links with Prev and next link with page numbers ///////////////// echo "<table align = 'center' width='50%'><tr><td align='left' width='30%'>"; //// if our variable $back is equal to 0 or more then only we will display the link to move back //////// if($back >=0) { print "<a href='$page_name?start=$back'>PREV</a>"; } //////////////// Let us display the page links at center. We will not display the current page as a link /////////// echo "</td><td align=center width='30%'>"; $i=0; $l=1; for($i=0;$i < $nume;$i=$i+$limit){ if($i <> $eu){ echo " <a href='$page_name?start=$i'>$l</a> "; } else { echo "$l";} /// Current page is not displayed as link and given font color red $l=$l+1; } echo "</td><td align='right' width='30%'>"; ///////////// If we are not in the last page then Next link will be displayed. Here we check that ///// if($this1 < $nume) { print "<a href='$page_name?start=$next'>NEXT</a>";} echo "</td></tr></table>"; } } ?> Quote Link to comment https://forums.phpfreaks.com/topic/260364-advanced-search/#findComment-1334785 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.