Page 1 of 1

Simply search script help required

Posted: Tue Feb 08, 2005 4:14 am
by mhouldridge
Hi,

I had a search script running using just a search field. here is the sql code which worked;

Code: Select all

$result = mysql_query("SELECT * FROM dedicated WHERE customer LIKE '%$search%'");
I want to add a selection box. The selection box will contain a range of columns that are created within my database, i.e. type, IP, software and so on.

Here is what I tried, but failed with;

Code: Select all

$result = mysql_query("SELECT * FROM dedicated WHERE '%$selection%' LIKE '%$search%'");
I also included above this;

Code: Select all

$search=$_POSTї"search"];
Here is the complete code which worked for the search field without the selection box;

Code: Select all

<?
//connect to mysql
//change user and password to your mySQL name and password
mysql_connect("localhost","giacom-admin","snooker"); 
	
//select which database you want to edit
mysql_select_db("audit"); 

$search=$_POST&#1111;"search"];

//get the mysql and store them in $result
//change whatevertable to the mysql table you're using
//change whatevercolumn to the column in the table you want to search
$result = mysql_query("SELECT * FROM dedicated WHERE customer LIKE  '%$search%'"); 

//grab all the content
while($r=mysql_fetch_array($result))
&#123;	
   //the format is $variable = $r&#1111;"nameofmysqlcolumn"];
   //modify these to match your mysql table columns
  
   $asset=$r&#1111;"asset"];
   $title=$r&#1111;"title"];
   $customer=$r&#1111;"customer"];
   $type=$r&#1111;"type"];
   $IP=$r&#1111;"IP"];
   $os=$r&#1111;"os"];
   
   //display the row
   echo "$asset <br> $title <br> $customer <br> $type <br> $IP <br> $os <br>";
&#125;
?>

feyd | I'm getting tired of editing your posts.

Posted: Tue Feb 08, 2005 4:27 am
by feyd
have you noticed that in all the MySQL examples there are no wildcards in field references? Have you also noticed that single and double quotes are strings to MySQL?