mardi 23 décembre 2014

searching through entire database php script



$tableArray = array('tbl_course','tbl_faculty');
if(!empty($_POST["searchField"]))
{
$search=$_POST["searchField"];
foreach( $tableArray as $tblArry)
{
$out .= $tblArry.";";
$sql_search = "select * from ".$tblArry." where ";
$sql_search_fields = Array();
$sql2 = "SHOW COLUMNS FROM ".$tblArry;
$rs2 =mysql_query($sql2);
if(mysql_num_rows($rs2)>0){
while($r2 = mysql_fetch_array($rs2)){
$colum = $r2[0];
$sql_search_fields[] = $colum." like('%".$search."%')";
}
}
$sql_search .= implode(" OR ", $sql_search_fields);
$rs3 = mysql_query($sql_search);

}
}


The problem is I want to display results from databas. The script is looping through columns of 2 tables and is creating a SQL statement based on that.


The only problem I am facing is how can I fetch data from the resultset r3?





Aucun commentaire:

Enregistrer un commentaire