Re: trouble with MySQL 'LIKE' command

From: Date: Sat, 05 May 2001 05:43:52 +0000
Subject: Re: trouble with MySQL 'LIKE' command
References: 1 2 3  Groups: php.windows 
Request: Send a blank email to php-windows+get-7310@lists.php.net to get a copy of this message
<? //search.php mysql_connect($host,$user,$pw); mysql_select_db($db); echo genSearch($table,$ID,$search,$host,$user,$pw,$db); if(isset($search)){ echo genData($table,$ID,$search); } /*********** fucntions ********/ function genSearch($table,$ID,$search,$host,$user,$pw,$db){ $r="<table bgcolor='#D0D0D0'>"; $r.="<tr><td><form action='search.php'></td></tr>"; $r.="<tr><td>Host:</td><td><input type=text name=host value=$host></td></tr>"; $r.="<tr><td>User</td><td><input type=text name=user value=$user></td></tr>"; $r.="<tr><td>Password</td><td><input type=password name=pw value=$pw></td></tr>"; $r.="<tr><td>Database</td><td><input type=text name=db value=$db></td></tr>"; $r.="<tr><td>Table:</td><td><input type=text name=table value=$table></td></tr>"; $r.="<tr><td>Field</td><td><input type=text name=ID value=$ID></td></tr>"; $r.="<tr><td>Search</td><td><input type=text name=search value=$search></td></tr>"; $r.="<tr><td></td></tr><tr><td><input type=submit></form></td></tr></table>"; return $r; } function genData($table,$ID,$search){ $sql=" select * from $table where lower($ID) like '%".strtolower($search)."%' "; $sql_result=mysql_query($sql) or die($sql); $r ="<br><table><tr><td bgcolor='#D0D0D0'>Table: $table Field: $ID </td></tr>"; $c=0; while($result=mysql_fetch_array($sql_result)){ $c++; $r.="<tr> "; for($ii=0;$ii<count($result);$ii++){ $color=($ii%2==0)?'#D0DCE0':'#DDDDDD'; $r.= " <td bgcolor=$color> ".htmlSpecialChars(stripslashes($result[$ii]))." </td> "; } $r.="</tr> "; } $r.="</table><b>$sql</b>"; return " Matches: ".$c.$r; } ?> ----- Original Message ----- From: "r.gelstharp" <r.gelstharp@ntlworld.com> To: <php-windows@lists.php.net> Sent: Saturday, May 05, 2001 2:28 AM Subject: Re: [PHP-WIN] trouble with MySQL 'LIKE' command > Done like you recommended with the select....like '%".$var."%' but it still > gives me empty rows of data. > > Everytime I try and search for something it returns with 7 rows of data, all > of which are blank. I'm using the basic mysql_num_rows to get the number of > rows of data it retrieves, and I'm using a WHILE($data = > mysql_fetch_array($sql_result)) to output the rows of data. > > If it's not the SQL statement, what could be doing this? I ask in case > you've heard this problem mentioned by some thick newbie like meself before. > > > > -- > PHP Windows Mailing List (http://www.php.net/) > To unsubscribe, e-mail: php-windows-unsubscribe@lists.php.net > For additional commands, e-mail: php-windows-help@lists.php.net > To contact the list administrators, e-mail: php-list-admin@lists.php.net > >

« previous php.windows (#7310) next »