Man you got me in the scripting mood...
I think this is pretty useful to have on a site

<?
//searchDB.php
mysql_connect($host,$user,$pw);


 echo genSearch($table,$ID,$search,$host,$user,$pw,$db);
if(isset($search)){
echo genData($db,$table,$ID,$search);
 }

/*********** fucntions ********/
function genSearch($table,$ID,$search,$host,$user,$pw,$db){
      $dbs=mysql_list_dbs();
      $num_db=mysql_num_rows($dbs);
      $ddb="<select name=db>";
    for($d=0;$d<$num_db;$d++){
      $ddb.="<option
".selected($db,mysql_db_name($dbs,$d)).">".mysql_db_name($dbs,$d)."</option>
";
     }
    $ddb.="</select>";



    @mysql_select_db($db);
     $tbs=@mysql_list_tables($db);
     $num_tb=@mysql_num_rows($tbs);
     $tb="<select name=table>";
    for($d=0;$d<$num_tb;$d++){
      $tb.="<option
".selected($table,@mysql_tablename($tbs,$d)).">".@mysql_tablename($tbs,$d)."
</option>";
     }
    $tb.="</select>";



     $fl=@mysql_list_fields($db,$table);
     $num_fd=@mysql_num_fields($fl);
     $fd="<select name=ID>";
    for($d=0;$d<$num_fd;$d++){
      $fd.="<option
".selected($ID,@mysql_field_name($fl,$d)).">".@mysql_field_name($fl,$d)."</o
ption>";
     }
    $fd.="</select>";



      $r="<table bgcolor='#D0D0D0'>";
      $r.="<tr><td><form method=post action='searchDB.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> $ddb </td></tr>";
      $r.="<tr><td>Table</td><td> $tb </td></tr>";
      $r.="<tr><td>Field</td><td> $fd </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 selected($a,$b){
   return ($a==$b)?"selected":"";
 }

function genData($db,$table,$ID,$search){



   $fields =@mysql_list_fields($db,$table);//could have $link as 3rd
argument
   $num=@mysql_num_fields($fields);

 $r ="<br><table><tr>";

   for($f=0;$f<$num;$f++){
    $r.="<td bgcolor='#D0DCE0'>".@mysql_field_name($fields,$f)."</td>";
   }
    $r.="</tr>";



 $sql=" select * from $table where lower($ID) like
'%".strtolower($search)."%' ";
 $sql_result=@mysql_query($sql);

 $c=0;
while($result=@mysql_fetch_array($sql_result)){
 $c++;
  $r.="<tr> ";
    for($ii=0;$ii<count($result);$ii++){
     $color=($c%2==0)?'#D0DCE0':'#DDDDDD';
    $r.= " <td bgcolor=$color>
".htmlSpecialChars(stripslashes($result[$ii]))." </td> ";

    }
 $r.="</tr> ";

    }
$r.="</table>";
return "<br><b>$sql</b><br><br> Matches: ".$c."<br>".$r;
}



?>

> ----- Original Message -----
> From: "r.gelstharp" <[EMAIL PROTECTED]>
> To: <[EMAIL PROTECTED]>
> 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: [EMAIL PROTECTED]
> > For additional commands, e-mail: [EMAIL PROTECTED]
> > To contact the list administrators, e-mail: [EMAIL PROTECTED]
> >
> >
>
> --
> PHP Windows Mailing List (http://www.php.net/)
> To unsubscribe, e-mail: [EMAIL PROTECTED]
> For additional commands, e-mail: [EMAIL PROTECTED]
> To contact the list administrators, e-mail: [EMAIL PROTECTED]
>
>

-- 
PHP Windows Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]

Reply via email to