include_once("library/config.php"); ?>
$where = getSearchWhereCondition();// " AND sts = 'Show' ";
$tables = "";
include_once("process/search_parameters.php");
// for getting randoem celebrant ids
$random_cel_ids = "";
$random_rows=0;
$sql = "SELECT
DISTINCT(c.celebrant_id)
FROM celebrants AS c $tables
WHERE 1 $where
ORDER BY rand() ";
// mush have photo check
$must_photo_random_cel_ids="";
if($is_photo=="Yes")
{
$res = $db->ExecuteQuery($sql);
while(list($celebrant_id)=$res->FetchAsArray())
{
$sql_cel_photo = "SELECT photo1, photo2, photo3, thumbnail FROM celebrants WHERE celebrant_id='$celebrant_id' ";
$rs_cel_photo = $db->ExecuteQuery($sql_cel_photo);
list($photo1, $photo2, $photo3, $thumbnail)=$rs_cel_photo->FetchAsArray();
// for photo
$photo="";
if($thumbnail == "p1")
{
$photo = $photo1;
}
elseif($thumbnail == "p2")
{
$photo = $photo2;
}
elseif($thumbnail == "p3")
{
$photo = $photo3;
}
else
{
$photo = $photo1;
}
// For Photo Exists Check!!
$file = CELEBRANTS_DIR.$photo;
if(file_exists($file) && !empty($photo))
{
$must_photo_random_cel_ids .= "$celebrant_id, "; // add id only when photo is exists!
}
}
if(!empty($must_photo_random_cel_ids))
{
$where_must_photo_random_cel_ids = substr($must_photo_random_cel_ids, 0, strlen($must_photo_random_cel_ids)-2);
$where .= " AND c.celebrant_id IN ($where_must_photo_random_cel_ids) ";
}
}
//
$sql = "SELECT DISTINCT(c.celebrant_id) FROM celebrants AS c $tables WHERE 1 $where ORDER BY rand()";
if(isset($_SESSION['cr_random_cel_ids']))
{
$random_cel_ids = $_SESSION['cr_random_cel_ids'];
$random_cel_ids_array = explode(", ", $random_cel_ids);
$random_rows = count($random_cel_ids_array);
}
else
{
if($is_photo=="Yes")
{
$random_cel_ids = $must_photo_random_cel_ids;
}
else
{
$res = $db->ExecuteQuery($sql);
while(list($celebrant_id)=$res->FetchAsArray())
{
$random_cel_ids .= "$celebrant_id, ";
}
}
if(!empty($random_cel_ids))
{
$random_cel_ids = substr($random_cel_ids, 0, strlen($random_cel_ids)-2);
$random_cel_ids_array = explode(", ", $random_cel_ids);
$random_rows = count($random_cel_ids_array);
$_SESSION['cr_random_cel_ids'] = $random_cel_ids;
}
}
//
/*
echo "
SQL: ".$sql."
";
echo "
Random IDs: ".$random_cel_ids."
";
echo "
Random Rows: ".$random_rows."
";
*/
// exit;
?>