Weird Wildcard Search
| From: | Manuel | Date: | Thu, 12 Oct 2000 13:37:54 +0000 |
| Subject: | Weird Wildcard Search | ||
| Groups: | php.db | ||
| Request: | Send a blank email to php-db+get-3551@lists.php.net to get a copy of this message | ||
Hi all,
I have a weird problem when doing my wildcard search.
I have a search.php3 form (with about 10 criterias) which will call the sresults.php3.
The first round always works fine but the second time is very erratic.
Questions:
1) Is there any part that I did wrongly?
2) How can I make the $ref sent by search.php3 global - able to use by any file?
I tried <? global $ref; ?> and it didn't seem to work.
3) Is there anywhere else that I can read up on this or anyone has any sample code?
I have consulted these book but it didn't help.
MySQL by Paul DuBios (New Riders)
PHP Programming by Castanetto, Rawat, Schumann, Scollo, Veliath (Wrox)
MySQL and mSQL by Yarger, Reese & King (O'Reilly)
Example of my run results:
search.php3 - %$ref% = '30'
First round is fine - sqlstmt = "SELECT * from my_table WHERE ref like '%30%'"
Second round using the next 15 record gave me
sqlstmt - "SELECT * from my_table WHERE ref like '0%'"
If I use only $ref% - string starts with it works.
search.php3 - $ref% = '30'
First round is fine - sqlstmt = "SELECT * from my_table WHERE ref like '30%'"
Second round using the next 15 record gave me
sqlstmt - "SELECT * from my_table WHERE ref like '30%'"
Extract of my coding. (partial)
*******************************
filename - sresults.php3
$MaxRow = 15;
if ($REQUEST_METHOD=='POST')
{
$searchstmt = "SELECT * from my_table WHERE ";
if ($ref)
$searchstmt .= "ref like '%$ref%' and ";
.
.
$stmt = substr($searchstmt, 0, strlen($searchstmt)-4);
$sqlstmt = $stmt . " ORDER BY ref DESC";
} // if POST
.
.
[ db browsing using the LIMIT ]
echo " <a href=\"sresults.php3?sqlstmt=$sqlstmt&CR=$CR&RL=$y\">[Next]</a>";
$sqlstmt = stripslashes("$sqlstmt");
sqlstmt = $sqlstmt . " LIMIT $RL,$MaxRow";
Sorry for the long posting.