Thursday, November 13, 2008

PHP Source Code: How to search in database

//connect to MySQL
$connect = mysql_connect(localhost,"root","password")
or die ("Hey loser, check your server connection.");
//make sure we’re using the right database
mysql_select_db("your schema") or die(mysql_error());
$s=$_POST['t1'];
$q1="select column_name from table_name where br like '$s%' ";
$query=mysql_query($q1);
$num=mysql_numrows($query);
$i=0;
while($i<$num)
{
$rst=mysql_result($query,$i,"br");
echo $rst;
echo "
";
$i++;
}
?>

No comments: