| Mailing List | | Home | | MySQL General - General MySQL discussion | | MaxDB - Everything about MaxDB, formerly known as SAP DB | | MySQL on Win32 - Runing MySQL on Windows 9x/Me/NT/2000/XP | | Java Help - Mostly related to the MySQL Connector/J driver | | ODBC - ODBC with the MySQL Connector/ODBC driver | | Perl - Perl support for MySQL with DBI and DBD::mysql | | MySQL++ - Programming with the C++ API to MySQL |
|
|
  | |  | Not getting matching records | Not getting matching records 2004-06-10 - By Dean Urmson
Back > > I have a TBL of users and I have created a search screen where you can
type in
> > first or last name and it will retrieve the appropriate records. Here is
the statement:
> > "Select * from STUDENTS WHERE FName LIKE '% " .$_REQUEST[ 'searchit ']. "% '
> > OR LName LIKE '% " . $_REQUEST[ 'searchit ']. "% ' OR idStudent LIKE '% "
> > .$_REQUEST[ 'searchit ']. "% ' "
I 'm assuming you 're using PHP with MySQL because of the reference to
$_REQUEST and using . To concatenate.
It could be a case, whitespace or data type issue.
Try using:
"SELECT
*
FROM
students
WHERE
lower( trim( FName ) ) LIKE '% " . strtolower( trim(
$_REQUEST[ 'searchit '] ) ) . "% '
OR
lower( trim( LName ) ) LIKE '% " . strtolower( trim(
$_REQUEST[ 'searchit '] ) ) . "% '
OR
lower( trim( idStudent ) ) LIKE '% ". strtolower( trim(
$_REQUEST[ 'searchit '] ) ) . "% ' "
If your idStudent field is a numeric data type then you need to do an
equality comparision rather than a like...
"SELECT
*
FROM
students
WHERE
lower( trim( FName ) ) LIKE '% " . strtolower( trim(
$_REQUEST[ 'searchit '] ) ) . "% '
OR
lower( trim( LName ) ) LIKE '% " . strtolower( trim(
$_REQUEST[ 'searchit '] ) ) . "% '
OR
idStudent = ". $_REQUEST[ 'searchit ']
If this doesn 't work please post the table structure (describe tablename)
and your PHP script.
Cheers
Dean
--
MySQL General Mailing List
For list archives:
http://lists.mysql.com/mysql
To unsubscribe:
http://lists.mysql.com/mysql?unsub=mysql
@(protected)
|
|
 |