Jump to content

Search Filter From Mysql


kumpel

Recommended Posts

Hi, I am having a problem getting my script to filter my search results. I have a script that allows ALL my data to appear in pagination form from Mysql, I also have a script that uses an array to allow one to refine a search by 4 criteria.My problem is 1) I cannot get the refined search script to work?2) How do I combine the two to allow a refined search and to put it in paginated form?Can anyone help?I have attached the 2 scripts belowPAGINATION SCRIPT (working)<!doctype html public "-//w3c//dtd html 3.2//en"><html><head><title>Plus2net.com paging script in PHP</title><meta name="GENERATOR" content="Arachnophilia 4.0"><meta name="FORMATTER" content="Arachnophilia 4.0"></head><body bgcolor="#ffffff" text="#000000" link="#0000ff" vlink="#800080" alink="#ff0000"><?$con = mysql_connect("mysql5.domainplanet.at", "xxxxxxx", "xxxxxxxx");if (!$con) { die('Could not connect: ' . mysql_error()); }mysql_select_db("xxxxyyyy", $con);$result = mysql_query("SELECT * FROM dort");$page_name="demo_paging1.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 = 10; // 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///////$query2=" SELECT * FROM dort";$result2=mysql_query($query2);echo mysql_error();$nume=mysql_num_rows($result2);/////// The variable nume above will store the total number of records in the table/////////////// Now let us print the table headers ////////////////$bgcolor="#3399FF";echo "<TABLE width=65% align=center cellpadding=5 cellspacing=5> <tr>";echo "<td bgcolor='99FFFF' > <font face='arial,verdana,helvetica' color='#F00303' size='4'>Was</font></td>";echo "<td bgcolor='99FFFF' > <font face='arial,verdana,helvetica' color='#F00303' size='4'>Bundesland</font></td>";echo "<td bgcolor='99FFFF' > <font face='arial,verdana,helvetica' color='#F00303' size='4'>Bezirk</font></td>";echo "<td bgcolor='99FFFF' > <font face='arial,verdana,helvetica' color='#F00303' size='4'>Ort</font></td>";echo "<td bgcolor='99FFFF' > <font face='arial,verdana,helvetica' color='#F00303' size='4'>Beschreibung</font></td>";echo "<td bgcolor='99FFFF' > <font face='arial,verdana,helvetica' color='#F00303' size='4'>Anfangdatum</font></td>";////////////// Now let us start executing the query with variables $eu and $limit set at the top of the page///////////$query=" SELECT * FROM dort limit $eu, $limit ";$result=mysql_query($query);echo mysql_error();//////////////// Now we will display the returned records in side the rows of the table/////////while($noticia = mysql_fetch_array($result)){if($bgcolor=='#f1f1f1'){$bgcolor='#ffffff';}else{$bgcolor='#f1f1f1';}echo "<tr >";echo "<td align=left bgcolor=$bgcolor id='title'> <font face='Verdana' size='2'>$noticia[Was]</font></td>"; echo "<td align=left bgcolor=$bgcolor id='title'> <font face='Verdana' size='2'>$noticia[bundesland]</font></td>"; echo "<td align=left bgcolor=$bgcolor id='title'> <font face='Verdana' size='2'>$noticia[bezirk]</font></td>"; echo "<td align=left bgcolor=$bgcolor id='title'> <font face='Verdana' size='2'>$noticia[Ort]</font></td>"; echo "<td align=left bgcolor=$bgcolor id='title'> <font face='Verdana' size='2'>$noticia[beschreibung]</font></td>"; echo "<td align=left bgcolor=$bgcolor id='title'> <font face='Verdana' size='2'>$noticia[AnfangDatum]</font></td>"; echo "</tr>";}echo "</table>";////////////////////////////// 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'><font face='Verdana' size='2'>PREV</font></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='80%'>";$i=0;$l=1;for($i=0;$i < $nume;$i=$i+$limit){if($i <> $eu){echo " <a href='$page_name?start=$i'><font face='Verdana' size='2'>$l</font></a> ";}else { echo "<font face='Verdana' size='4' color=red>$l</font>";} /// 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'><font face='Verdana' size='2'>NEXT</font></a>";} echo "</td></tr></table>";}// end of if checking sufficient records are there to display bottom navigational link. ?></body></html>SEARCH SCRIPT<?php $con = mysql_connect("mysql5.domainplanet.at", "xxxxxx", "xxxxxx");if (!$con) { die('Could not connect: ' . mysql_error()); }mysql_select_db("outofafrica", $con); ############################################################################################## function search($was,$bundesland,$bezirk) { $values = array($was,$bundesland,$bezirk); $condition = array('Was=\''.$was.'\' ','Bundesland=\''.$bundesland.'\' ','Bezirk=\''.$bezirk.'\''); function not_null($val) { return($val!=''); } //$callback = $this->not_null(); /*$function_body = "return (isset($val));"; echo $function_name = create_function('$val', $function_body);*/ $filteredArr = array_filter($values,'not_null'); $fil_keys = array_keys($filteredArr); $totFil = count($fil_keys); for($i=0;$i<$totFil;$i++) { $filter_key =$fil_keys[$i]; $result[] = $condition[$filter_key]; } $condition_res = implode(’ AND ‘,$result); $query = "SELECT * FROM dort WHERE $condition_res "; return $query; } ############################################################################################## $was = $_POST['was']; $bundesland = $_POST['Bundesland']; $bezirk = $_POST['bezirk']; echo $searchRes = search($was,$bundesland,$bezirk); ?>

Link to comment
Share on other sites

Wow, HTML 3.2 huh? The classics are alive and well it seems.What happens when you run the filter script? The result is that it should print out a SQL query when you submit to that page from a form, is that what you're seeing? It looks like the script was copied and pasted from a blog or something and some of the quotes got messed up, are you seeing any errors?At least on this line the quotes need to be fixed:$condition_res = implode(’ AND ‘,$result);

Link to comment
Share on other sites

Hi, yes it is a little old :) I did indeed copy it from a one of the forums and changed what I could to make it work. I am not a programmer as you can se but am learning!When I run it it just returns all the data from the MYsql dbase, no error comes up.Thanks for replying.

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...