Forums

PHP

This topic is locked

Problem with a simple search

Posted 24 Aug 2001 19:59:27
1
has voted
24 Aug 2001 19:59:27 Frank Surget posted:
Hi Folks,
I'm pretty new to PHP and Phakt but have quite a bit of experience with UD 4. I don't have any problem connecting to MySql server through jdbc or creating my page. My problem arises when I attempt to create a search on a field called "Name". I'm trying to submit a query from a text field in a form and am not sure how to set it up in the recordset. I have tried filter the recordset on "form value". Here is the code generated:
$Recordset1__MMColParam = "1";
if (isset($HTTP_POST_VARS["Name"]))
{$Recordset1__MMColParam = $HTTP_POST_VARS["Name"];}

Here is the query:
$Recordset1=$connSearch->Execute("SELECT * FROM Business WHERE Name LIKE '" . ($Recordset1__MMColParam) . "'" or DIE($connSearch->ErrorMsg());

Can anyone help a PHP newbie?
Thanks
Frank

Replies

Replied 24 Aug 2001 20:01:02
24 Aug 2001 20:01:02 Frank Surget replied:
Oh, and BTW I've tried Post and Get...
which one should I use??
Thanks again.
FS
Replied 25 Aug 2001 03:12:10
25 Aug 2001 03:12:10 Tim Green replied:
You say you are having problems, yet you neglect to mention exactly what those problems are.

Are error messages being generated ? What is your system spec ? What are the symptoms of your problem ?

Without knowing any of this information, it is like looking for a needle in a haystack.

For more information, please read the FAQ (the link is in my signature).

So that you know, the 'Form Value' method you have chosen (or POST method) is the best option for this kind of thing.

Tim Green

Extension & PHP TalkZone Manager
<font size=1>-------------------------------------------
<i>Please read the Forum FAQ before posting
a question to this TalkZone.</i>
-------------------------------------------
www.UDzone.com : A dynamic Dreamweaver,
Ultradev and Fireworks site for developers
by developers.
-------------------------------------------</font id=size1>
Replied 25 Aug 2001 12:27:37
25 Aug 2001 12:27:37 Bruno Mairlot replied:
<BLOCKQUOTE id=quote><font size=1 face="Verdana, Arial, Helvetica" id=quote>quote:<hr height=1 noshade id=quote>

Here is the query:
$Recordset1=$connSearch-&gt;Execute("SELECT * FROM Business WHERE Name LIKE '" . ($Recordset1__MMColParam) . "'" or DIE($connSearch-&gt;ErrorMsg());
<hr height=1 noshade id=quote></BLOCKQUOTE id=quote></font id=quote><font face="Verdana, Arial, Helvetica" size=2 id=quote>

Don't forget that the LIKE keyword is almost like = but can work with wildcard (like % or _ ).

Are you looking for the exact name or every row where the name contains it ?

If this is the case, the you may use the following query :

$Recordset1=$connSearch-&gt;Execute("SELECT * FROM Business WHERE Name <b>REGEXP</b> '" . ($Recordset1__MMColParam)."'" or DIE($connSearch-&gt;ErrorMsg());

But as Tim said, if you don't tell us what exactly you problem is, we can't help.

Bruno


"First they laugh at you, then they fight you, then you Win..." Ghandi

Edited by - Maehdros on 08/25/2001 12:28:35
Replied 25 Aug 2001 14:03:39
25 Aug 2001 14:03:39 Frank Surget replied:
Thanks guys for the responses,
I really don't get an error message. It just doesn't display any results on the results.php page. I just realized that I used to add a single quote and a % to both sides of the MM_whatever to make the LIKE work correctly. I'm going to try that and the REGEXP like Maehdros suggested. BTW, what does REGEXP do?
Thanks
Frank
Replied 25 Aug 2001 15:45:19
25 Aug 2001 15:45:19 Bruno Mairlot replied:
<BLOCKQUOTE id=quote><font size=1 face="Verdana, Arial, Helvetica" id=quote>quote:<hr height=1 noshade id=quote>
BTW, what does REGEXP do?
<hr height=1 noshade id=quote></BLOCKQUOTE id=quote></font id=quote><font face="Verdana, Arial, Helvetica" size=2 id=quote>

REGEXP check the string against a regular expression.

I don't know wich server you're using, and if this server support REGEXP, but it can be used undre MySQL.

Here is the url to know more about regular expression under MySQL :

Tim doesn't like that I post MySQL specific information, but it's always better than nothing...<img src=../images/dmxzone/forum/icon_smile.gif border=0 align=middle>www.mysql.com/doc/R/e/Regexp.html


"First they laugh at you, then they fight you, then you Win..." Ghandi

Reply to this topic