简体   繁体   中英

Multiple Search Pagination with PHP and MySQL

I have the following query below which uses the GET value of fname and lname to compare it to a database table:

$query = mysql_query("SELECT * FROM pages
                      WHERE `fname` = '$fname' OR `lname` = '$lname'
                      LIMIT $start, $perpage")
         or die(mysqli_error());

When I run the code, it only puts into account the 'lname' = '$lname' statement.

What I would like it to do is search for either the fname or lname variables, or both if they both of them are set.

query with LIKE

$query = mysql_query("SELECT * FROM pages
                        WHERE `fname` LIKE '%$fname%' AND `lname` LIKE '%$lname%'
                        LIMIT $start, $perpage
                    ");

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