Problem with Programming Search Results

Discussion in 'PHP' started by rubenmajor, Jan 24, 2006.

  1. #1
    Hello,

    First of all, I would like to start off with an apology for asking a probably simple question and also if this is not the correct place for this posting. I just need some help!:eek:

    I have some basic knowledge with PHP, but my developer & designer seem unable to fix this problem and have asked me to contact the software people who seem not to know as well.

    I have a Roommate website and have purchased a new program. Users can create both "looking for room" and "have a room" ads, but they can only find results for "looking for a room" and cannot find results for "looking for a room." What should I do?

    The site address is: www.roommatesonline.net

    Any help would be enormously appreciated.
     
    rubenmajor, Jan 24, 2006 IP
  2. GetWebHost

    GetWebHost Active Member

    Messages:
    735
    Likes Received:
    10
    Best Answers:
    0
    Trophy Points:
    78
    #2
    It should be better if you post part of the code here :)
     
    GetWebHost, Jan 24, 2006 IP
  3. rubenmajor

    rubenmajor Well-Known Member

    Messages:
    152
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    103
    #3
    Sorry. I had it up before and I thought it was taking up a lot of room. I will post it below. Thank you.
     
    rubenmajor, Jan 24, 2006 IP
  4. rubenmajor

    rubenmajor Well-Known Member

    Messages:
    152
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    103
    #4
    I have included a copy of the .tpl file referring to the results as well as the .php file.

    results.php
    <?

    include "common.php";

    if ($uid == 0) { security_error(); }

    if ((isset($_GET["cid"])) && ($_GET["cid"] > 0)) {
    $cid = $_GET["cid"];
    } else {
    $cid = 0;
    }
    if ($_GET["a"] != "search") {
    check_security("ads", $_GET["cid"], $uid);
    }
    if ((isset($_GET["p"])) && ($_GET["p"] > 0)) {
    $p = $_GET["p"];
    } else {
    $p = 0;
    }
    if ((isset($_GET["ord"])) && ($_GET["ord"] > 0) && ($_GET["ord"] < 4)) {
    $ord = $_GET["ord"];
    } else {
    $ord = 1;
    }

    $any_area = 0;
    if (count($_GET["areas"]) > 0) {
    foreach ($_GET["areas"] as $a) {
    if($a == 'ANY') {
    $any_area = 1;
    break;
    }
    }
    }
    if($any_area) {
    unset($_GET["areas"]);
    }

    if($_GET["city"] == 'ANY') {
    unset($_GET["city"]);
    }


    // check what type this ad is:
    if ($_GET["a"] == "search") {
    $ad_type = $_GET["ad_type"];
    } else {
    $rs = $dbconn->Execute("select ad_type from ads where id = $cid");
    $ad_type = $rs->fields[0];
    }
    $sql_query = "
    select a.id, a.users_id, users.username, users.sex, users.age, users.smoking,
    a.rent1, a.rent2, a.rent, a.rent_deposit,
    a.city, a.areas_id, a.date_move_in, a.date_available,
    users.date_online, unix_timestamp(users.date_online) as online_ts,
    to_days(a.date_available) - to_days(Now()) as available_days,
    users.emoticon, users.pic
    ";
    $where_add_type = '';
    if ($ad_type > 0) {
    $where_add_type = "and a.ad_type = ".$ad_type;
    }
    if ($ad_type == 1) {
    if ($_GET["a"] == "search") {
    $wh_cl = u_search_looking_wh();
    } else {
    $wh_cl = u_looking_wh($cid);
    }
    $sql_query .= "
    from ads a, users
    where users.id = a.users_id and $wh_cl $where_add_type
    ";
    $count_query = "
    select count(*)
    from ads a, users
    where users.id = a.users_id and $wh_cl $where_add_type
    ";
    } else {
    if ($_GET["a"] == "search") {
    $wh_cl = u_search_have_wh();
    } else {
    $wh_cl = u_have_wh($cid);
    }
    $sql_query .= ", b.id as ads_areas_id
    from ads a, users, ads_areas b
    where users.id = a.users_id and b.ads_id = a.id and $wh_cl $where_add_type
    ";
    $count_query = "
    select count(*)
    from ads a, users, ads_areas b
    where users.id = a.users_id and b.ads_id = a.id and $wh_cl $where_add_type
    ";
    }

    if ($_GET["a"] == "search") {
    if ($_GET["sex"] > 0) {
    $sql_query .= " and users.sex = '".$_GET["sex"]."'";
    $count_query .= " and users.sex = '".$_GET["sex"]."'";
    }
    } else {
    $user_wh_cl = u_user_wh($cid);
    if ($user_wh_cl != "") {
    $sql_query .= " and ".$user_wh_cl;
    $count_query .= " and ".$user_wh_cl;
    }
    }

    if ($ord == 1) {
    $order = "users.date_online desc";
    } elseif ($ord == 2) {
    if ($ad_type == 1) {
    $order = "rent";
    } else {
    $order = "rent1 desc";
    }
    } elseif ($ord == 3) {
    if ($ad_type == 1) {
    $order = "date_available desc";
    } else {
    $order = "date_move_in desc";
    }
    }
    $sql_query .= " order by $order";

    // creating navigation
    if ($_GET["a"] == "search") {
    if (count($_GET["areas"]) > 0) {
    $arr = array();
    foreach ($_GET["areas"] as $a) {
    $arr[] = "areas[]=".$a;
    }
    $areas_list = join("&", $arr);
    } else {
    $areas_list = "";
    }

    $srch_str = "&a=search&ad_type=".$_GET["ad_type"]."&room_type=".$_GET["room_type"]."&city=".$_GET["city"]."&$areas_list&rent1=".$_GET["rent1"]."&rent2=".$_GET["rent2"]."&sex=".$_GET["sex"];
    } else {
    $srch_str = "";
    }
    $rs = $dbconn->Execute($count_query);
    $smarty->assign("navigation", create_navigation($rs->fields[0], $config["ads_per_page"], "ord=$ord&cid=$cid".$srch_str, "results.php", $p));

    $ads_total = $rs->fields[0];
    $ads_start = $p*$config["ads_per_page"]+1;
    $ads_stop = $ads_start+$config["ads_per_page"]-1;
    if ($ads_stop > $ads_total) {
    $ads_stop = $ads_total;
    }
    if ($ads_start > $ads_total) {
    $ads_start = $ads_total;
    }
    $smarty->assign(array(
    "ads_total" => $ads_total,
    "ads_start" => $ads_start,
    "ads_stop" => $ads_stop
    ));


    $values = array();
    $i = 0;
    $rs = $dbconn->PageExecute($sql_query, $config["ads_per_page"], $p+1);
    while (!$rs->EOF) {
    $row = $rs->GetRowAssoc(false);
    $values[$i]["id"] = $row["id"];
    $values[$i]["users_id"] = $row["users_id"];
    $values[$i]["username"] = stripslashes($row["username"]);
    $values[$i]["sex"] = ($row["sex"] > 0) ? $config["sex"][$row["sex"]] : "";
    $values[$i]["age"] = $row["age"];
    $values[$i]["smoking"] = ($row["smoking"] > 0) ? $config["smoking_res"][$row["smoking"]] : "";
    $values[$i]["rent1"] = $row["rent1"];
    $values[$i]["rent2"] = $row["rent2"];
    $values[$i]["rent"] = $row["rent"];
    $values[$i]["rent_deposit"] = $row["rent_deposit"];
    $values[$i]["city"] = get_value("cities", $row["city"]);
    $values[$i]["area"] = get_value("cities_areas", $row["areas_id"]);


    $area_arr = array();
    if($values[$i]["area"])
    $area_arr[] = $values[$i]["area"];
    // selectin areas user is looking a flat in
    $rs1 = $dbconn->Execute("
    select b.name
    from ads_areas a, cities_areas b
    where b.id = a.areas_id and a.ads_id = " . $row["id"] . "
    ");
    while (!$rs1->EOF) {
    if(!in_array(stripslashes($rs1->fields[0]), $area_arr))
    $area_arr[] = stripslashes($rs1->fields[0]);
    $rs1->MoveNext();
    }
    if (count($area_arr) > 0) {
    $values[$i]["area"] = join(", ", $area_arr);
    }




    $values[$i]["ads_area"] = get_value("cities_areas", $row["ads_areas_id"]);
    $values[$i]["date_move_in"] = date_to_french($row["date_move_in"]);
    $values[$i]["date_available"] = date_to_french($row["date_available"]);
    $values[$i]["available_days"] = ($row["available_days"]<=0) ? "<strong>Available Now!</strong>" : $values[$i]["date_available"] ."(". $row["available_days"]." days)";
    $values[$i]["users_emoticon"] = $row["emoticon"];
    $values[$i]["users_pic"] = $row["pic"];
    $values[$i]["date_online"] = GetOnlineStatus($row["online_ts"], date_to_french($row["date_online"]));

    $i++;
    $rs->MoveNext();
    }

    $smarty->assign(array(
    "values" => $values,
    "ad_type" => $ad_type,
    "cid" => $cid,
    "p" => $p,
    "ord" => $ord,
    "return_url" => urlencode(((!empty($_SERVER["REQUEST_URI"]))?$_SERVER["REQUEST_URI"]:"results.php"))
    ));

    $smarty->display("results.tpl");
    exit();


    function u_search_looking_wh() {
    $wh_arr = array("a.status_finished = 1", "a.status_active = 1");
    if ($ad_type > 0) {
    $wh_arr[] = "a.ad_type = ".$ad_type;
    }
    // choosing city areas to search for
    if (count($_GET["areas"]) > 0) {
    $wh_arr[] = "a.areas_id in (".join(",", $_GET["areas"]).")";
    }
    if ($_GET["city"] > 0) {
    $wh_arr[] = "a.city = ".$_GET["city"];
    }

    if ($_GET["room_type"] > 0) {
    $wh_arr[] = "a.room_types_id = ".$_GET["room_type"];
    }
    if ($_GET["rent1"] > 0) {
    $wh_arr[] = "a.rent >= ".$_GET["rent1"];
    }
    if ($_GET["rent2"] > 0) {
    $wh_arr[] = "a.rent <= ".$_GET["rent2"];
    }

    return (count($wh_arr) > 0) ? join(" and ", $wh_arr) : "";
    }

    function u_search_have_wh() {
    $wh_arr = array("a.status_finished = 1", "a.status_active = 1");
    // choosing city areas to search for
    if (count($_GET["areas"]) > 0) {
    $wh_arr[] = "a.areas_id in (".join(",", $_GET["areas"]).")";
    }
    if ($_GET["city"] > 0) {
    $wh_arr[] = "a.city = ".$_GET["city"];
    }

    if ($_GET["rent1"] > 0) {
    $wh_arr[] = "(a.rent1 = 0 or a.rent1 <= ".$_GET["rent1"].")";
    }
    if ($_GET["rent2"] > 0) {
    $wh_arr[] = "(a.rent2 = 0 or a.rent2 >= ".$_GET["rent2"].")";
    }

    return (count($wh_arr) > 0) ? join(" and ", $wh_arr) : "";
    }

    ?>

    results.tpl
    {include file="top.tpl"}

    <TABLE WIDTH=760 BORDER=0 CELLPADDING=0 CELLSPACING=2 height="100%">
    <TR valign="top">
    <TD width="100%">
    <TABLE WIDTH=100% BORDER=0 CELLPADDING=0 CELLSPACING=0 height="100%">
    <TR valign="top">
    <TD width="565" class="wnd" style="BORDER-BOTTOM:0px;">
    <TABLE WIDTH=100% BORDER=0 CELLPADDING=2 CELLSPACING=0>
    <TR>
    <TD HEIGHT=36 ALT=""><img src="image/hads.jpg" border=0></TD>
    </TR>
    </TABLE>
    </TD>
    <td HEIGHT=36 WIDTH="180" align="center" valign="top" class="wnd" style="BORDER-TOP:0px;BORDER-LEFT:0px;BORDER-RIGHT:0px;">
    {if $uid > 0}
    <b><a href="search.php?{$SID}"><h4>Quick Search</h4></a></b>
    {else}
    &nbsp;
    {/if}
    </td>
    </TR>
    <TR valign="top">
    <TD width="760" colspan="2" class="wnd" style="BORDER-TOP:0px;">
    <table border="0" width="100%" id="table57">
    <tr>
    <td colspan="4">
    <table border="0" id="table58">
    <tr>
    <td>
    <img src="image/dot.jpg" align="absmiddle">&nbsp;Matching Ads: {$ads_start} - {$ads_stop} of {$ads_total}

    <INPUT class="btn" onclick="document.location='mail.php?{$SID}&a=new&return_url={$return_url}'" type=button value="create mail >>" name=B60>
    </td>
    <td>Sort by: </td>
    <td>
    <INPUT class="btn" onclick="document.location='results.php?sid={$sid}&cid={$cid}&ord=1'" type=button value="last online >>" name=B60>
    </td>
    <td>
    <INPUT class="btn" onclick="document.location='results.php?sid={$sid}&cid={$cid}&ord=2'" type=button value="rent >>" name=B68>
    </td>
    <td>
    <INPUT class="btn" onclick="document.location='results.php?sid={$sid}&cid={$cid}&ord=3'" type=button value="date >>" name=B69>
    </td>
    </tr>
    </table>
    </td>
    </tr>

    <tr>
    <td>
    <table WIDTH=100% BORDER=0 CELLPADDING=5 CELLSPACING=1 height="100%" bgcolor="#E0E0E0">
    <tr bgcolor="#ECECEC">
    <td width="10%" align="center"><b><img src="image/dot.jpg" align="absmiddle">&nbsp;Nick</b></td>
    {if $ad_type == 2}
    <td width="20%" align="center"><b><img src="image/dot.jpg" align="absmiddle">&nbsp;Monthly Rent</b></td>
    <td width="20%" align="center"><b><img src="image/dot.jpg" align="absmiddle">&nbsp;Residence</b></td>
    <td width="20%" align="center"><b><img src="image/dot.jpg" align="absmiddle">&nbsp;Available date</b></td>
    {else}
    <td width="20%" align="center"><b><img src="image/dot.jpg" align="absmiddle">&nbsp;Max Rent</b></td>
    <td width="20%" align="center"><b><img src="image/dot.jpg" align="absmiddle">&nbsp;Residence</b></td>
    <td width="20%" align="center"><b><img src="image/dot.jpg" align="absmiddle">&nbsp;Move in date</b></td>
    {/if}
    <td width="15%" align="center"><b><img src="image/dot.jpg" align="absmiddle">&nbsp;Last activity</b></td>
    <td width="15%" align="center"><b>&nbsp;</b></td>
    </tr>
    {section name=sec1 loop=$values}
    <tr bgcolor="FFFFFF">
    <td><a class="cian" href="view.php?{$SID}&cid={$values[sec1].id}&return_url={$return_url}">
    {$values[sec1].username}{if $values[sec1].users_pic > 0}&nbsp;<img src="files/user_pics/{$values[sec1].users_id}.jpg" height="100" width="100">&nbsp;{/if}</a>
    </td>
    {if $ad_type == 2}
    <td>${$values[sec1].rent} per month {if $values[sec1].rent_deposit > 0} + deposit{/if}</td>
    <td>{$values[sec1].city} ({$values[sec1].area})</td>
    <td>{$values[sec1].available_days}</td>
    {else}
    <td>{if $values[sec1].rent2 > 0}
    ${$values[sec1].rent2} per month
    {elseif $values[sec1].rent1 > 0}
    ${$values[sec1].rent1} per month
    {else}
    Doesn't matter
    {/if}
    </td>
    <td>{$values[sec1].city} ({$values[sec1].area})</td>
    <td>{$values[sec1].date_move_in}</td>
    {/if}
    <td>{$values[sec1].date_online}</td>
    <td>
    <INPUT class="btn" onclick="document.location='view.php?{$SID}&cid={$values[sec1].id}&return_url={$return_url}'" type=button value="more info >>" name=B53>
    </td>
    </tr>
    <tr bgcolor="#ECECEC">
    <td {if $ad_type == 1}colspan="6"{else}colspan="5"{/if}>
    About me: {if $values[sec1].sex != ""}{$values[sec1].sex} {/if}
    {if $values[sec1].age > 0}{$values[sec1].age} years old{/if} {if $values[sec1].smoking != ""}{$values[sec1].smoking}{/if}
    </td>
    </tr>
    {sectionelse}
    <tr bgcolor="FFFFFF">
    <td {if $ad_type == 1}colspan="6"{else}colspan="5"{/if} align="center">No results <b> - Go Back & Try "Does not Matter" for City</b></td>
    </tr>
    {/section}
    </table>
    </td>
    </tr>
    <tr><td>&nbsp;&nbsp;&nbsp;{if $navigation}{$navigation}{/if}</td></tr>

    </table>
    </TD>
    </TR>
    </TABLE>
    </TD>
    </TR>
    </TABLE>

    {include file="bottom.tpl"}
     
    rubenmajor, Jan 24, 2006 IP
  5. themole

    themole Peon

    Messages:
    82
    Likes Received:
    7
    Best Answers:
    0
    Trophy Points:
    0
    #5
    what do these return?

    $wh_cl = u_search_looking_wh();
    $wh_cl = u_looking_wh($cid);
    *edit* found it... doh.

    also, could you use the code tag around the code? Assuming there's any formatting, it will hopefully make things easier to read.

    -the mole
     
    themole, Jan 24, 2006 IP
  6. rubenmajor

    rubenmajor Well-Known Member

    Messages:
    152
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    103
    #6
    I'll check it out and let you know and I'll resend. Thank you.
     
    rubenmajor, Jan 24, 2006 IP
  7. rubenmajor

    rubenmajor Well-Known Member

    Messages:
    152
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    103
    #7
    results.php
    
    <?
    
    include "common.php";
    
    if ($uid == 0) { security_error(); }
    
    if ((isset($_GET["cid"])) && ($_GET["cid"] > 0)) {
    	$cid = $_GET["cid"];
    } else {
    	$cid = 0;
    }
    if ($_GET["a"] != "search") {
    	check_security("ads", $_GET["cid"], $uid);
    }
    if ((isset($_GET["p"])) && ($_GET["p"] > 0)) {
    	$p = $_GET["p"];
    } else {
    	$p = 0;
    }
    if ((isset($_GET["ord"])) && ($_GET["ord"] > 0) && ($_GET["ord"] < 4)) {
    	$ord = $_GET["ord"];
    } else {
    	$ord = 1;
    }
    
    	$any_area = 0;
    	if (count($_GET["areas"]) > 0) {
    		foreach ($_GET["areas"] as $a) {
    			if($a == 'ANY') {
    				$any_area = 1;
    				break;
    			}
    		}
    	}
    	if($any_area) {
    		unset($_GET["areas"]);
    	}
    
    	if($_GET["city"] == 'ANY') {
    		unset($_GET["city"]);
    	}
    
    
    // check what type this ad is:
    if ($_GET["a"] == "search") {
    	$ad_type = $_GET["ad_type"];
    } else {
    	$rs = $dbconn->Execute("select ad_type from ads where id = $cid");
    	$ad_type = $rs->fields[0];
    }
    $sql_query = "
    	select a.id, a.users_id, users.username, users.sex, users.age, users.smoking,
    			a.rent1, a.rent2, a.rent, a.rent_deposit,
    			a.city, a.areas_id, a.date_move_in, a.date_available,
    			users.date_online, unix_timestamp(users.date_online) as online_ts,
    			to_days(a.date_available) - to_days(Now()) as available_days,
    			users.emoticon, users.pic
    ";
    $where_add_type = '';
    if ($ad_type > 0) {
    	$where_add_type = "and a.ad_type = ".$ad_type;
    }
    if ($ad_type == 1) {
    	if ($_GET["a"] == "search") {
    		$wh_cl = u_search_looking_wh();
    	} else {
    		$wh_cl = u_looking_wh($cid);
    	}
    	$sql_query .= "
    		from ads a, users
    		where users.id = a.users_id and $wh_cl $where_add_type 
    	";
    	$count_query = "
    		select count(*)
    			from ads a, users
    			where users.id = a.users_id and $wh_cl $where_add_type
    	";
    } else {
    	if ($_GET["a"] == "search") {
    		$wh_cl = u_search_have_wh();
    	} else {
    		$wh_cl = u_have_wh($cid);
    	}
    	$sql_query .= ", b.id as ads_areas_id
    		from ads a, users, ads_areas b
    		where users.id = a.users_id and b.ads_id = a.id and $wh_cl $where_add_type
    	";
    	$count_query = "
    		select count(*)
    			from ads a, users, ads_areas b
    			where users.id = a.users_id and b.ads_id = a.id and $wh_cl $where_add_type
    	";
    }
    
    if ($_GET["a"] == "search") {
    	if ($_GET["sex"] > 0) {
    		$sql_query .= " and users.sex = '".$_GET["sex"]."'";
    		$count_query .= " and users.sex = '".$_GET["sex"]."'";
    	}
    } else {
    	$user_wh_cl = u_user_wh($cid);
    	if ($user_wh_cl != "") {
    		$sql_query .= " and ".$user_wh_cl;
    		$count_query .= " and ".$user_wh_cl;
    	}
    }
    
    if ($ord == 1) {
    	$order = "users.date_online desc";
    } elseif ($ord == 2) {
    	if ($ad_type == 1) {
    		$order = "rent";
    	} else {
    		$order = "rent1 desc";
    	}
    } elseif ($ord == 3) {
    	if ($ad_type == 1) {
    		$order = "date_available desc";
    	} else {
    		$order = "date_move_in desc";
    	}
    }
    $sql_query .= " order by $order";
    
    // creating navigation
    if ($_GET["a"] == "search") {
    	if (count($_GET["areas"]) > 0) {
    		$arr = array();
    		foreach ($_GET["areas"] as $a) {
    			$arr[] = "areas[]=".$a;
    		}
    		$areas_list = join("&", $arr);
    	} else {
    		$areas_list = "";
    	}
    	
    	$srch_str = "&a=search&ad_type=".$_GET["ad_type"]."&room_type=".$_GET["room_type"]."&city=".$_GET["city"]."&$areas_list&rent1=".$_GET["rent1"]."&rent2=".$_GET["rent2"]."&sex=".$_GET["sex"];
    } else {
    	$srch_str = "";
    }
    $rs = $dbconn->Execute($count_query);
    $smarty->assign("navigation", create_navigation($rs->fields[0], $config["ads_per_page"], "ord=$ord&cid=$cid".$srch_str, "results.php", $p));
    
    $ads_total = $rs->fields[0];
    $ads_start = $p*$config["ads_per_page"]+1;
    $ads_stop = $ads_start+$config["ads_per_page"]-1;
    if ($ads_stop > $ads_total) {
    	$ads_stop = $ads_total;
    }
    if ($ads_start > $ads_total) {
    	$ads_start = $ads_total;
    }
    $smarty->assign(array(
    	"ads_total"	=> $ads_total,
    	"ads_start"	=> $ads_start,
    	"ads_stop"	=> $ads_stop
    ));
    
    
    $values = array();
    $i = 0;
    $rs = $dbconn->PageExecute($sql_query, $config["ads_per_page"], $p+1);
    while (!$rs->EOF) {
    	$row = $rs->GetRowAssoc(false);
    	$values[$i]["id"] = $row["id"];
    	$values[$i]["users_id"] = $row["users_id"];
    	$values[$i]["username"] = stripslashes($row["username"]);
    	$values[$i]["sex"] = ($row["sex"] > 0) ? $config["sex"][$row["sex"]] : "";
    	$values[$i]["age"] = $row["age"];
    	$values[$i]["smoking"] = ($row["smoking"] > 0) ? $config["smoking_res"][$row["smoking"]] : "";
    	$values[$i]["rent1"] = $row["rent1"];
    	$values[$i]["rent2"] = $row["rent2"];
    	$values[$i]["rent"] = $row["rent"];
    	$values[$i]["rent_deposit"] = $row["rent_deposit"];
    	$values[$i]["city"] = get_value("cities", $row["city"]);
    	$values[$i]["area"] = get_value("cities_areas", $row["areas_id"]);
    
    
    	$area_arr = array();
    	if($values[$i]["area"])
    		$area_arr[] = $values[$i]["area"];
            // selectin areas user is looking a flat in
            $rs1 = $dbconn->Execute("
                    select b.name
                            from ads_areas a, cities_areas b
                            where b.id = a.areas_id and a.ads_id = " . $row["id"] . "
            ");
            while (!$rs1->EOF) {
    		if(!in_array(stripslashes($rs1->fields[0]), $area_arr))
                    	$area_arr[] = stripslashes($rs1->fields[0]);
                    $rs1->MoveNext();
            }
            if (count($area_arr) > 0) {
    		$values[$i]["area"] = join(", ", $area_arr);
            }
    
    
    
    
    	$values[$i]["ads_area"] = get_value("cities_areas", $row["ads_areas_id"]);
    	$values[$i]["date_move_in"] = date_to_french($row["date_move_in"]);
    	$values[$i]["date_available"] = date_to_french($row["date_available"]);
    	$values[$i]["available_days"] = ($row["available_days"]<=0) ? "<strong>Available Now!</strong>" : $values[$i]["date_available"] ."(". $row["available_days"]." days)";
    	$values[$i]["users_emoticon"] = $row["emoticon"];
    	$values[$i]["users_pic"] = $row["pic"];
    	$values[$i]["date_online"] = GetOnlineStatus($row["online_ts"], date_to_french($row["date_online"]));
    
    	$i++;
    	$rs->MoveNext();
    }
    
    $smarty->assign(array(
    	"values"	=> $values,
    	"ad_type"	=> $ad_type,
    	"cid"		=> $cid,
    	"p"		=> $p,
    	"ord"		=> $ord,
    	"return_url"	=> urlencode(((!empty($_SERVER["REQUEST_URI"]))?$_SERVER["REQUEST_URI"]:"results.php"))
    ));
    
    $smarty->display("results.tpl");
    exit();
    
    
    function u_search_looking_wh() {
    	$wh_arr = array("a.status_finished = 1", "a.status_active = 1");
    	if ($ad_type > 0) {
    		$wh_arr[] = "a.ad_type = ".$ad_type;
    	}
    	// choosing city areas to search for
    	if (count($_GET["areas"]) > 0) {
    		$wh_arr[] = "a.areas_id in (".join(",", $_GET["areas"]).")";
    	}
    	if ($_GET["city"] > 0) {
    		$wh_arr[] = "a.city = ".$_GET["city"];
    	}
    
    	if ($_GET["room_type"] > 0) {
    		$wh_arr[] = "a.room_types_id = ".$_GET["room_type"];
    	}
    	if ($_GET["rent1"] > 0) {
    		$wh_arr[] = "a.rent >= ".$_GET["rent1"];
    	}
    	if ($_GET["rent2"] > 0) {
    		$wh_arr[] = "a.rent <= ".$_GET["rent2"];
    	}
    
    	return (count($wh_arr) > 0) ? join(" and ", $wh_arr) : "";
    }
    
    function u_search_have_wh() {
    	$wh_arr = array("a.status_finished = 1", "a.status_active = 1");
    	// choosing city areas to search for
    	if (count($_GET["areas"]) > 0) {
    		$wh_arr[] = "a.areas_id in (".join(",", $_GET["areas"]).")";
    	}
    	if ($_GET["city"] > 0) {
    		$wh_arr[] = "a.city = ".$_GET["city"];
    	}
    
    	if ($_GET["rent1"] > 0) {
    		$wh_arr[] = "(a.rent1 = 0 or a.rent1 <= ".$_GET["rent1"].")";
    	}
    	if ($_GET["rent2"] > 0) {
    		$wh_arr[] = "(a.rent2 = 0 or a.rent2 >= ".$_GET["rent2"].")";
    	}
    
    	return (count($wh_arr) > 0) ? join(" and ", $wh_arr) : "";
    }
    
    ?>
    
    Code (markup):
    results.tpl
    
    {include file="top.tpl"}
    
    <TABLE WIDTH=760 BORDER=0 CELLPADDING=0 CELLSPACING=2 height="100%">
    <TR valign="top">
    	<TD width="100%">
    		<TABLE WIDTH=100% BORDER=0 CELLPADDING=0 CELLSPACING=0 height="100%">
    		<TR valign="top">
    			<TD width="565" class="wnd" style="BORDER-BOTTOM:0px;">
    				<TABLE WIDTH=100% BORDER=0 CELLPADDING=2 CELLSPACING=0>
    				<TR>
    					<TD HEIGHT=36 ALT=""><img src="image/hads.jpg" border=0></TD>
    				</TR>
    				</TABLE>
    			</TD>
    			<td HEIGHT=36 WIDTH="180" align="center" valign="top" class="wnd" style="BORDER-TOP:0px;BORDER-LEFT:0px;BORDER-RIGHT:0px;">
    			{if $uid > 0}
    				<b><a href="search.php?{$SID}"><h4>Quick Search</h4></a></b>
    			{else}
    				&nbsp;
    			{/if}
    			</td>
    		</TR>
    		<TR valign="top">
    			<TD width="760" colspan="2" class="wnd" style="BORDER-TOP:0px;">
    				<table border="0" width="100%" id="table57">
    			            <tr>
    			                <td colspan="4">
    			                <table border="0" id="table58">
    			                    <tr>
    			                        <td> 
    						<img src="image/dot.jpg" align="absmiddle">&nbsp;Matching Ads: {$ads_start} - {$ads_stop} of {$ads_total}
    
    						<INPUT class="btn" onclick="document.location='mail.php?{$SID}&a=new&return_url={$return_url}'" type=button value="create mail >>" name=B60>
    						</td>
    				                <td>Sort by: </td>
    						<td> 
    							<INPUT class="btn"  onclick="document.location='results.php?sid={$sid}&cid={$cid}&ord=1'" type=button value="last online >>" name=B60>
    						</td>
    			                        <td> 
    							<INPUT class="btn"  onclick="document.location='results.php?sid={$sid}&cid={$cid}&ord=2'" type=button value="rent >>" name=B68>
    						</td>
    						<td> 
    							<INPUT class="btn"  onclick="document.location='results.php?sid={$sid}&cid={$cid}&ord=3'" type=button value="date >>" name=B69>
    						</td>
    			                    </tr>
    			                </table>
    			                </td>
    			            </tr>
    
    				    <tr>
    					<td>
    					    <table WIDTH=100% BORDER=0 CELLPADDING=5 CELLSPACING=1 height="100%" bgcolor="#E0E0E0">
    				            <tr bgcolor="#ECECEC">
    				                <td width="10%" align="center"><b><img src="image/dot.jpg" align="absmiddle">&nbsp;Nick</b></td>
    						{if $ad_type == 2}
    				                <td width="20%" align="center"><b><img src="image/dot.jpg" align="absmiddle">&nbsp;Monthly Rent</b></td>
    				                <td width="20%" align="center"><b><img src="image/dot.jpg" align="absmiddle">&nbsp;Residence</b></td>
    				                <td width="20%" align="center"><b><img src="image/dot.jpg" align="absmiddle">&nbsp;Available date</b></td>
    						{else}
    				                <td width="20%" align="center"><b><img src="image/dot.jpg" align="absmiddle">&nbsp;Max Rent</b></td>
    								<td width="20%" align="center"><b><img src="image/dot.jpg" align="absmiddle">&nbsp;Residence</b></td>
    				                <td width="20%" align="center"><b><img src="image/dot.jpg" align="absmiddle">&nbsp;Move in date</b></td>
    						{/if}
    				                <td width="15%" align="center"><b><img src="image/dot.jpg" align="absmiddle">&nbsp;Last activity</b></td>
    				                <td width="15%" align="center"><b>&nbsp;</b></td>
    				            </tr>
    					    {section name=sec1 loop=$values}
    				            <tr bgcolor="FFFFFF">
    						<td><a class="cian" href="view.php?{$SID}&cid={$values[sec1].id}&return_url={$return_url}">
    							{$values[sec1].username}{if $values[sec1].users_pic > 0}&nbsp;<img src="files/user_pics/{$values[sec1].users_id}.jpg" height="100" width="100">&nbsp;{/if}</a>
    						</td>
    						{if $ad_type == 2}
    				                <td>${$values[sec1].rent} per month {if $values[sec1].rent_deposit > 0} + deposit{/if}</td>
    				                <td>{$values[sec1].city} ({$values[sec1].area})</td>
    				                <td>{$values[sec1].available_days}</td>
    						{else}
    						<td>{if $values[sec1].rent2 > 0}
    					        	   ${$values[sec1].rent2}  per month
    						    {elseif $values[sec1].rent1 > 0}
    						          ${$values[sec1].rent1} per month
    						    {else}
    						            Doesn't matter
    						    {/if}
    						</td>
    						<td>{$values[sec1].city} ({$values[sec1].area})</td>
    						<td>{$values[sec1].date_move_in}</td>
    						{/if}
    				                <td>{$values[sec1].date_online}</td>
    				                <td> 
    							<INPUT class="btn" onclick="document.location='view.php?{$SID}&cid={$values[sec1].id}&return_url={$return_url}'" type=button value="more info >>" name=B53>
    						</td>
    				            </tr>
    				            <tr bgcolor="#ECECEC">
    				                <td {if $ad_type == 1}colspan="6"{else}colspan="5"{/if}>
    				                	About me: {if $values[sec1].sex != ""}{$values[sec1].sex} {/if}
    					                {if $values[sec1].age > 0}{$values[sec1].age} years old{/if} {if $values[sec1].smoking != ""}{$values[sec1].smoking}{/if}
    						</td>
    				            </tr>
    					    {sectionelse}
    					    <tr bgcolor="FFFFFF">
    					        <td {if $ad_type == 1}colspan="6"{else}colspan="5"{/if} align="center">No results <b> - Go Back & Try "Does not Matter" for City</b></td>
    					    </tr>
    					    {/section}
    					    </table>
    					</td>
    				    </tr>
    					<tr><td>&nbsp;&nbsp;&nbsp;{if $navigation}{$navigation}{/if}</td></tr>
    					
    				</table>
    			</TD>
    		</TR>
    		</TABLE>
    	</TD>
    </TR>
    </TABLE>
    {include file="bottom.tpl"}
    
    Code (markup):
     
    rubenmajor, Jan 24, 2006 IP