开发者

Searching multiple values

So far i have created a search box, which searches the primary key of my database.

How can i modify my php query to search multiple values in my database.

eg: If i search the name of the car instead of the VIN (primary key) it will show all the results matching the search value. This

    $query = ("SELECT * FROM cars
WHERE VIN='$VIN'");     

This is my form :

<form name="search" action="http://www.deakin.edu.au/~sjrem/SIT104_3/cars.php" method="post">
<h2> Search for a car of you开发者_如何学JAVAr choice </h2>   


<table border="0">
<tr>
<td><input type="text" name="VIN" /> </td>
</tr>

</table> 



                       <p>
<input type="submit" name="action" value="search" />
</FORM>


Have you tried something like $query = ("SELECT * FROM cars WHERE VIN='$VIN' OR name LIKE '%$VIN%'");?

"LIKE" uses % as wildcard, so it will find all cars that have $VIN in their name.

But anyway make sure to mysql_real_escape_string() your parameter $VIN first, to prevent SQL injections!


Use the following query:

$query = ("SELECT * FROM cars WHERE Name LIKE '%$txtName%'");

NOTE:: Wildcard % is been used at the beginning and end to return all names having your search word anywhere in the field.


something like this might work for you

$query = ("SELECT * FROM cars WHERE VIN='$VIN' OR CARS='$VIN'"); 
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜