简体   繁体   中英

php filter search results

hello I developped a search form with php,which is working perfectly,but I would like to filter for example alphabetically,so I defined some anchors in my html document A| B | ....

In my php document,I added:

        $search=$_POST['query']//query is the name of input in a form,on the same html doc
        $letter=$_GET['by'];

from my sql query,

        $sql=SELECT Title FROM table where Title LIKE %search%;

I added :

          if(isset($letter)){
             $sql .="AND Name LIKE '$letter' ";
           }

My problem is that when I click for example on the link "A" it always display all entry corresponding of all titles having names beginning of letter"A".(my Table has 2 columns,Title and Name) So I would like when I do a search to filter the results(getting when I click on "A" titles for which names begin by "A" and only those returned on the result of the search)

I hope you have a space before the AND; but you need to wildcard the LIKE

$sql .=" AND Name LIKE '$letter%' ";

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM