Forum Moderators: coopster

Message Too Old, No Replies

Zebra Pagination Error

problem using where

         

ricksum

2:35 pm on Sep 4, 2014 (gmt 0)

10+ Year Member



I have a script I got from: [github.com...] which accesses a mysql db. I also have a form that calls the example2.php and passes a data field.

What I'm trying to do is use a WHERE clause to select the records desired. The example2 program has been modified as follows:
pertinent code:

$MySQL = '
SELECT
SQL_CALC_FOUND_ROWS
country
FROM
countries
ORDER BY
country
LIMIT
' . (($pagination->get_page() - 1) * $records_per_page) . ', ' . $records_per_page . '
';

and the modified code is
 $MySQL = '
SELECT
SQL_CALC_FOUND_ROWS
`last`,`first`,`mate`,`address`
FROM `homeownersnew` WHERE LIKE $last."%"

LIMIT
' . (($pagination->get_page() - 1) * $records_per_page) . ', ' . $records_per_page . '
';

and the form field value is
{$last = "s"; //$_POST['Last'];
which gives an error: Home Owners in Belmont Farms Last Name is s. 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 '"%" LIMIT 18, 18' at line 4
HOWEVER, if I change the WHERE to: WHERE `last` LIKE "s%" it works.
I have some (limited) knowledge of php and mysqli.
Any and all help appreciated. Thanks

ricksum

8:25 pm on Sep 5, 2014 (gmt 0)

10+ Year Member



Found the answer ... it was because of my ignorance of mysql. I was NOT formatting the where clause correctly.