Originally Posted by
sogate
by the way, the situation here is this: first, the name is being searched in table 1 and if not found, then it will search the name to other table which is table 2. I hope this will clarify things.
since pag-reformat sa ako pc, wla ko ka-install ug apache/php/mysql so dili ko sure kung wla ni errors... but gina-review nako ug ayu and I think wla ni error...
here's the code... wla lng nako gigamitan atong anti-sql injection... gitapulan ko..
PHP Code:
<?php
$keyword = $_POST['searchword'];
$query1 = "SELECT * FROM table1 WHERE name LIKE '%".$keyword."%'";
$query2 = "SELECT * FROM table2 WHERE name LIKE '%".$keyword."%'";
$result1 = mysql_query($query1) or die(mysql_error());
$result2 = mysql_query($query2) or die(mysql_error());
$num_rows1 = mysql_num_rows($result1);
$num_rows2 = mysql_num_rows($result2);
if ($num_rows1 == 0)
{
$finalResult = $result2;
} //end if
else //if num_rows1 != 0
{
$finalResult = $result1;
} //end else
while ($row = mysql_fetch_assoc($finalResult))
{
$name = $row['name'];
echo $name.'\n';
} //end while
?>