SitePoint Sponsor

User Tag List

Results 1 to 2 of 2
  1. #1
    SitePoint Member
    Join Date
    Nov 2004
    Location
    dallas
    Posts
    1
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Adding option to search page

    I have a little problem here. I am trying to add zip code radius search ability to my search page at the following URL:
    http://www.desirater.com/search.php

    now, i am a newbie and dont know how to do that, so if new users signs up he/she has to enter a zip code if within USA, and users can search him/hjer within a specific radius of a specific zip code.
    Any help will be appretiated.
    ---------------------
    <?php
    include("./admin/config.php");
    include("$include_path/common.php");
    include("$include_path/$table_file");
    include("$include_path/doc_head.php");
    include("$include_path/styles.php");

    global $HTTP_POST_VARS,$HTTP_GET_VARS,$HTTP_SESSION_VARS;

    global $_SESSION;

    if ($HTTP_POST_VARS!="")
    $_POST=$HTTP_POST_VARS;

    if ($HTTP_GET_VARS!="")
    $_GET=$HTTP_GET_VARS;

    if ($HTTP_SESSION_VARS!="")
    $_SESSION=$HTTP_SESSION_VARS;


    include ("Ads_new.php");
    include("$include_path/left.php");
    include("$include_path/right.php");


    $results = "";
    $member_search = " >> Member Search";

    if(isset($_GET['ss'])) {
    $results = " >> Search Results";
    $member_search = ' >> <a class="link01" href=" ' . $base_url . '/search.php?u=' . $_GET['u'] . '&amp;g=' . $_GET['g'] . '&amp;s=' . $_GET['s'] . '&amp;c=' . $_GET['c'] . '&amp;star='.$_GET['star'].'&amp;r='.$_GET['r'].'&amp;e='.$_GET['e'].'&amp;al=' . $_GET['al'] .'&amp;ah=' . $_GET['ah'] . '">Member Search</a>';
    $tpl->assign(array('RESULTS' => $results,
    'MEMBER_SEARCH' => $member_search));
    }


    if(isset($_GET['ss']))
    {
    $nav_search_username = "";
    if(isset($_GET['u']) && strlen($_GET['u'])) {
    $nav_search_username = addslashes(trim($_GET['u']));
    $search_username = ".*" . $nav_search_username . ".*";
    } else {
    $search_username = ".*";
    }

    $nav_search_low_age = 18;
    if(isset($_GET['al']) && strlen($_GET['al'])) {
    $nav_search_low_age = (int) $_GET['al'];
    $search_low_age = $nav_search_low_age;
    }

    $nav_search_high_age = 88;
    if(isset($_GET['ah']) && strlen($_GET['ah'])) {
    $nav_search_high_age = (int) $_GET['ah'];
    $search_high_age = $nav_search_high_age;
    }

    $nav_search_gender = "";
    $gender_sql = "";
    if(isset($_GET['g']) && strlen($_GET['g'])) {
    switch($_GET['g']) {
    case "m":
    $gender_sql = "and ( " . get_gender_types_sql("m") . ")";
    $nav_search_gender = "m";
    break;
    case "f":
    $gender_sql = "and ( " . get_gender_types_sql("f") . ")";
    $nav_search_gender = "f";
    break;
    }
    }

    $nav_search_state = "";
    if(isset($_GET['s']) && strlen($_GET['s'])) {
    $nav_search_state = $_GET['s'];
    $search_state = "%" . $nav_search_state . "%";
    } else {
    $search_state = "%%";
    }

    $nav_search_country = "";
    if(isset($_GET['c']) && strlen($_GET['c'])) {
    $nav_search_country = $_GET['c'];
    $search_country = "%" . $nav_search_country . "%";
    } else {
    $search_country = "%%";
    }

    $nav_search_starsign = "";
    if(isset($_GET['star']) && strlen($_GET['star'])) {
    $nav_search_starsign = $_GET['star'];
    $search_starsign = "%" . $nav_search_starsign . "%";
    } else {
    $search_starsign = "%%";
    }

    $nav_search_ethinisity = "";
    if(isset($_GET['e']) && strlen($_GET['e'])) {
    $nav_search_ethinisity = addslashes(trim($_GET['e']));
    $search_ethinisity = ".*" . $nav_search_ethinisity . ".*";
    } else {
    $search_ethinisity = "%%";
    }

    $nav_search_religion = "";
    if(isset($_GET['r']) && strlen($_GET['r'])) {
    $nav_search_religion = addslashes(trim($_GET['r']));
    $search_religion = ".*" . $nav_search_religion . ".*";
    } else {
    $search_religion = "%%";
    }

    $sort = isset($_GET['sort']) ? $_GET['sort'] : "";

    $tc_sql = "select count(*) as count from $tb_users where username REGEXP '$search_username' and age >= '$search_low_age' and age <= '$search_high_age' $gender_sql and state like '$search_state' and country like '$search_country' /*and star_sign like '$search_starsign' and ethnicity like '$search_ethinisity' and religion like '$search_religion'*/ and image_status = 'approved'";

    $tc_query = mysql_query($tc_sql) or die(mysql_error());

    $tc = (int) mysql_result($tc_query, 0, "count");

    if($tc > 0) {
    $nav_url = "$base_url/search.php?u=".$nav_search_username."&amp;g=".$nav_search_gender."&amp;s=".$nav_search_state."&amp;c=".$nav_search_country."&amp;star=".$nav_search_starsign."&amp;e=".$nav_search_ethinisity."&amp;r=".$nav_search_religion."&amp;al=".$nav_search_low_age."&amp;ah=".$nav_search_high_age."&amp;sort=".$sort ."&amp;ss=1&amp;";

    $nav = toplist_nav_links($tc, $search_users_per_page, $np, $ccp, $nav_url);
    $nav = '<span class="s9">' . $nav . '</span>';
    }

    switch ($sort) {
    case "username_asc" : $order_by = "username"; break;
    case "username_desc" : $order_by = "username desc"; break;
    case "age_asc" : $order_by = "age"; break;
    case "age_desc" : $order_by = "age desc"; break;
    case "user_type_asc" : $order_by = "user_type"; break;
    case "user_type_desc" : $order_by = "user_type desc"; break;
    case "total_ratings_asc" : $order_by = "total_ratings"; break;
    case "total_ratings_desc" : $order_by = "total_ratings desc"; break;
    case "total_comments_asc" : $order_by = "total_comments"; break;
    case "total_comments_desc" : $order_by = "total_comments desc"; break;
    case "total_points_asc" : $order_by = "total_points"; break;
    case "total_points_desc" : $order_by = "total_points desc"; break;
    case "avg_rating_asc" : $order_by = "average_rating"; break;
    case "avg_rating_desc" : $order_by = "average_rating desc"; break;
    default : $order_by = "average_rating desc"; break;
    }

    $sql = "select $tb_users.id as id, $tb_users.username as username, $tb_users.realname as realname, $tb_users.country as country, $tb_users.age as age, $tb_users.user_type as user_type, $tb_users.total_ratings as total_ratings, $tb_users.total_points as total_points, $tb_users.average_rating as average_rating, $tb_users.total_comments as total_comments from $tb_users where username REGEXP '$search_username' and age >= '$search_low_age' and age <= '$search_high_age' $gender_sql and state like '$search_state' and country like '$search_country' /* and star_sign like '$search_starsign' and ethnicity like '$search_ethinisity' and religion like '$search_religion'*/ and image_status = 'approved' order by $order_by limit $csr, $search_users_per_page";

    //echo " sql ".$sql;

    $time_start = getmicrotime();

    $query = mysql_query($sql) or die(mysql_error());

    $time_end = getmicrotime();

    $time = number_format($time_end - $time_start, 4);

    $a=0; $b=1; $c=1;

    $tpl->assign(array('TIME' => $time));

    if(isset($nav) && strlen($nav)) {
    $tpl->assign(array('NAV' => $nav));
    }

    if(mysql_num_rows($query)>0) {

    if($order_by == "username") {
    $order_username = "username_desc";
    } else {
    $order_username = "username_asc";
    }

    if($order_by == "age") {
    $order_age = "age_desc";
    } else {
    $order_age = "age_asc";
    }

    if($order_by == "total_comments desc") {
    $order_total_comments = "total_comments_asc";
    } else {
    $order_total_comments = "total_comments_desc";
    }

    if($order_by == "total_ratings desc") {
    $order_total_ratings = "total_ratings_asc";
    } else {
    $order_total_ratings = "total_ratings_desc";
    }


    if($order_by == "total_points desc") {
    $order_total_points = "total_points_asc";
    } else {
    $order_total_points = "total_points_desc";
    }


    if($order_by == "average_rating desc") {
    $order_avg_rating = "avg_rating_asc";
    } else {
    $order_avg_rating = "avg_rating_desc";
    }


    $tpl->assign(array('ORDER_USERNAME' => $order_username,
    'ORDER_AGE' => $order_age,
    'ORDER_TOTAL_COMMENTS' => $order_total_comments,
    'ORDER_TOTAL_RATINGS' => $order_total_ratings,
    'ORDER_TOTAL_POINTS' => $order_total_points,
    'ORDER_AVG_RATING' => $order_avg_rating,
    'NAV_SEARCH_USERNAME' => $nav_search_username,
    'NAV_SEARCH_GENDER' => $nav_search_gender,
    'NAV_SEARCH_STATE' => $nav_search_state,
    'NAV_SEARCH_COUNTRY' => $nav_search_country,
    'NAV_SEARCH_LOW_AGE' => $nav_search_low_age,
    'NAV_SEARCH_HIGH_AGE' => $nav_search_high_age,
    ));

    $i = 0;

    while($array=mysql_fetch_array($query)) {

    $alt = $i % 2 ? "alt1" : "alt2";
    $i++;

    if($array["country"]=="") {
    $array["country"] = "None.gif";
    }
    $short_entry = eregi_replace(".gif", "", $array["country"]);
    $country = eregi_replace("_", " ", $short_entry);

    $thumb_img = "<a href=\"$base_url/?i=$array[id]\" target=\"_top\" class=\"link01\">
    <img src=\"image1.php?id=$array[id]&p=1\" border=0 alt=\".: $array[username] :.\" title=\".: $array[username]:.\" width=50 height=50></a>";

    /*
    $tpl->assign(array('ALT' => $alt,
    'COUNTRY_FLAG' => $array['country'],
    'COUNTRY' => $country,
    'ID' => $array['id'],
    'USERNAME' => $array['username'],
    'AGE' => $array['age'],
    'TOTAL_COMMENTS' => $array['total_comments'],
    'TOTAL_RATINGS' => $array['total_ratings'],
    'TOTAL_POINTS' => $array['total_points'],
    'AVERAGE_RATING' => $array['average_rating']
    ));
    */

    $tpl->assign(array('ALT' => $alt,
    'THUMB_IMAGE' => $thumb_img,
    'COUNTRY' => $country,
    'ID' => $array['id'],
    'USERNAME' => $array['username'],
    'AGE' => $array['age'],
    'TOTAL_COMMENTS' => $array['total_comments'],
    'TOTAL_RATINGS' => $array['total_ratings'],
    'TOTAL_POINTS' => $array['total_points'],
    'AVERAGE_RATING' => $array['average_rating']
    ));

    $tpl->parse('ROWS_SEARCH_RESULT', '.row_search_result');

    $a++; $b++;
    }
    $tpl->parse('CONTENT_TABLE', 'search_results');
    } else {
    $tpl->parse('CONTENT_TABLE', 'search_not_found');
    }
    $content .= $tpl->fetch('CONTENT_TABLE');
    } else { // form


    $starsign_list = "<option>Aries</option>
    <option>Taurus</option>
    <option> Gemini</option>
    <option> Cancer</option>
    <option>Leo</option>
    <option>Virgo</option>
    <option>Libra</option>
    <option>Scorpio</option>
    <option>Sagittarius</option>
    <option>Capricorn</option>
    <option>Aquarius</option>
    <option>Pisces</option> ";

    $states_list = get_states_list(isset($_GET['s']) ? $_GET['s'] : "");
    $flags_list = getFlagList($base_path . "/images/flags", isset($_GET['c']) ? $_GET['c'] : "");
    $low_age_options = get_age_options(isset($_GET['al']) ? $_GET['al'] : $low_age_limit);
    $high_age_options = get_age_options(isset($_GET['ah']) ? $_GET['ah'] : $high_age_limit);
    $username1 = isset($_GET['u']) ? $_GET['u'] : "";
    $f_gender = (isset($_GET['g']) && $_GET['g'] == "f") ? " checked" : "";
    $m_gender = (isset($_GET['g']) && $_GET['g'] == "m") ? " checked" : "";
    $a_gender = (!isset($_GET['g']) || $_GET['g'] == "" || (!strlen($m_gender) && !strlen($f_gender))) ? " checked" : "";

    $tpl->assign(array('STATES_LIST' => $states_list,
    'FLAGS_LIST' => $flags_list,
    'LOW_AGE_OPTIONS' => $low_age_options,
    'HIGH_AGE_OPTIONS' => $high_age_options,
    'USERNAME1' => $username1,
    'F_GENDER' => $f_gender,
    'M_GENDER' => $m_gender,
    'A_GENDER' => $a_gender));
    $tpl->parse('CONTENT_TABLE', 'search_form');
    $search_form = $tpl->fetch('CONTENT_TABLE');
    }
    $tpl->parse('CONTENT_TABLE', 'search_content_table');
    $content = $tpl->fetch('CONTENT_TABLE');


    $final_output = table("Member Search", $content);

    $tpl->assign(array('CONTENT_TEXT' => $final_output));
    $tpl->parse('PAGE', 'main');
    $final_output = $tpl->fetch('PAGE');



    $final_output = final_output($final_output);

    //echo ($final_output);
    include ("copy.php");
    ?>
    -------------

  2. #2
    Non-Member St.'s Avatar
    Join Date
    Nov 2004
    Location
    Cloud #9
    Posts
    119
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    you realy think anybody will read all of this? 8)


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •