Thursday, December 17, 2009

Fetch Record form search string in php

fetch unique  row set passing query sting as parameter and search by its all word of string one by one merge all record and find unique row set and display them.

$dbc=mysql_query('host','username','pass');
mysql_select_db('databasename',$dbc);

$getTag=$_REQUEST['tags'];  //searching string

$arrFirst=array();
$arrSecond=array();


$queryExecute="select * from music where name like('%".$getTag."%') and status='y' or singer like('%".$getTag."%') and status='y' or language like('%".$getTag."%') and status='y' or main_cate like('%".$getTag."%') and status='y' or genure like('%".$getTag."%') and status='y' or placename like('%".$getTag."%') and status='y' or other_tag like ('%".$getTag."%') and status='y'";


$queryResult=mysql_query($queryExecute,$dbc);

while($row=mysql_fetch_array($queryResult)){

$arrFirst=array_merge($arrFirst,array($row[0]));

}

$findKeyTag=explode(" ",$getTag);

for($i=0;$i
$executequery="select * from music where name like('%".$findKeyTag[$i]."%') and status='y' or language='$findKeyTag[$i]' and status='y' or main_cate='$findKeyTag[$i]' and status='y' or guru='$findKeyTag[$i]' and status='y' or genure='$findKeyTag[$i]' and status='y' or lordname='$findKeyTag[$i]' and status='y' or other_tag like('%".$findKeyTag[$i]."%') and status='y'";

$result=mysql_query($executequery,$dbc);
while($row=mysql_fetch_array($result)){

$arrSecond=array_merge($arrSecond,array($row[0]));

}


}

$arrFinal1=array();
$arrFinal=array_unique(array_merge($arrFirst,$arrSecond));

$rsCount=count($arrFinal);
for($i=0;$i<$rsCount;$i++){

$arrFinal1=array_unique(array_merge($arrFinal1,$arrFinal));

}

if($rsCount>$display){

$pages=ceil($rsCount/$display);

}else{
$pages=1;
}



showRecord1($arrFinal1,$getTag,$dbc,$startNo);




function showRecord1($arr,$tag,$dbc,$start,$userId,$url){


$totalRecord=count($arr);
for($i=$start;$i<$start+10;$i++){


if($arr[$i]==""||!$arr[$i]){

     break;
}


$q="select * from music where id=$arr[$i]";
$result=mysql_query($q,$dbc);

while($row3=mysql_fetch_array($result)){

echo $row["id"];
}

   }

}

No comments:

Post a Comment