I’m trying to compare two $_GET inputs from a form and add them to an SQL statement if it finds something LIKE that in the database. Here is the SQL code.
<?php
include('db_connect.php');
$name1 = $_GET['name1'];
$name2 = $_GET['name2'];
$query="SELECT * FROM Stats WHERE `Name` LIKE '$_GET[name1]%' OR '$_GET[name2]%' ";
$res=mysql_query($query);
$num=mysql_numrows($res);
$i=0;
while($i< $num){
$Name = mysql_result($res, $i, "Name");
echo $Name;
$i++;
}
?>
This works for the first $_GET[name1] field, however I want to return More if name2 matches as well. Any ideas would be greatly appreciated.
Try to concatenate the strings:
You also need the
LIKE-operator when you useOR.Maybe it is also a problem that the function
mysql_numrows()is exactly calledmysql_num_rows().