RE: [PHP] SELECT BLAH WHERE BLAH LIKE BLAH not working

From: Date: Thu, 15 Feb 2001 04:29:06 +0000
Subject: RE: [PHP] SELECT BLAH WHERE BLAH LIKE BLAH not working
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-39817@lists.php.net to get a copy of this message
thanks ben it works :) Just one thing if i say enter just one letter .. how could i make it show more than just the one result? -----Original Message----- From: ben@host2.successfulhosting.com [mailto:ben@host2.successfulhosting.com]On Behalf Of Ben Peter Sent: Thursday, February 15, 2001 2:23 PM To: Peter Houchin Cc: PHP MAIL GROUP Subject: Re: [PHP] SELECT BLAH WHERE BLAH LIKE BLAH not working Peter, after querying the database, you need to fetch the returned values from the result before you can use them: > $result = mysql_query("SELECT company FROM resellers WHERE Company LIKE > '%$query%'"); $row = mysql_fetch_row($result); $company = $row[0]; OR (shorter): list($company)=mysql_fetch_row($result); > printf("<tr><td> $company </td></tr>\n"); otherwise, $company would not be set. Ben Peter Houchin wrote: > > Hiya, i was wondering if some one could help me with this ... i have a > little form where you can enter a value say company then on submit its ment > to check the db for value or one like it my sql line works fine > (mysql_error() shows nothing and it works from command line) .. > > . > . > . > <form name=search method=POST action="<? $PHP_SELF ?>"> > <input type="text" name="query"> > <input type="submit" name="submit" value="submit"> > </form> > <? if ($submit){ > echo "<TABLE BORDER=\"0\" CELLPADDING=\"3\" > CELLSPACING=\"1\" > BGCOLOR=\"#CCCCCC\" ALIGN=\"CENTER\">\n<tr > BGCOLOR=\"#CCCCCC\">\n<td > bgcolor=\"#006699\"><div align=\"center\"><font > face=\"Helvetica, > sans-serif\" size=\"3\" > color=\"#FFFFFF\"><b>Company</b> </td></tr>"; > $result = mysql_query("SELECT company FROM resellers WHERE Company LIKE > '%$query%'"); > printf("<tr><td> $company </td></tr>\n"); > echo "</table>"; > echo mysql_error(); > } > ?> > > Thanks in advance > > Peter -- PHP General Mailing List (http://www.php.net/) To unsubscribe, e-mail: php-general-unsubscribe@lists.php.net For additional commands, e-mail: php-general-help@lists.php.net To contact the list administrators, e-mail: php-list-admin@lists.php.net

« previous php.general (#39817) next »