Simply search script help required

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
User avatar
mhouldridge
Forum Contributor
Posts: 267
Joined: Wed Jan 26, 2005 5:13 am

Simply search script help required

Post 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.
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post 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?
Post Reply