Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 5966643
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T19:49:45+00:00 2026-05-22T19:49:45+00:00

i have this code on the server side: <?php header(‘Content-Type: text/html; charset=utf-8’); require ../general.variables.php;

  • 0

i have this code on the server side:

<?php
header('Content-Type: text/html; charset=utf-8');
require "../general.variables.php";
require "../functions_validation.php";
require "../functions_general.php";
require "../../db_con.php";

$keyword = mysql_real_escape_string($_POST["keyword"]);

$query = mysql_query("

    SELECT user_id, user_fullname, user_area, user_city, user_quarter, user_tmb
    FROM `migo_users`
    WHERE (
        user_fullname LIKE '%".$keyword."%' AND user_id NOT IN (".$superAdmins2string.")
    )
    ORDER BY tmb_set DESC, user_fname ASC
    LIMIT 7;
");

$i = 0;
while ($userInfo = mysql_fetch_array($query)) {

    $area_name = mysql_fetch_array(mysql_query("

        SELECT area_name
        FROM `migo_areas`
        WHERE
            area_id='".$userInfo['user_area']."';
    "));

    $city_name = mysql_fetch_array(mysql_query("

        SELECT city_name
        FROM `migo_cities`
        WHERE
            city_id='".$userInfo['user_city']."';
    "));

    if ($userInfo['user_quarter'] != 0) {

        $quarter_name = mysql_fetch_array(mysql_query("

            SELECT quarter_name
            FROM `migo_quarters`
            WHERE
                quarter_id='".$userInfo['user_quarter']."';
        "));
    }           
    else {
        $quarter_name['quarter_name'] = "";
    }   

    $rsl[$i]['user_id'] = $userInfo['user_id'];
    $rsl[$i]['user_fullname'] = $userInfo['user_fullname'];

    $rsl[$i]['user_area_name'] = $area_name['area_name'];
    $rsl[$i]['user_city_name'] = $city_name['city_name'];
    $rsl[$i]['user_quarter_name'] = $quarter_name['quarter_name'];

    $rsl[$i]['user_tmb'] = $userInfo['user_tmb'];

    $i++;
}

echo json_encode($rsl);
mysql_close();
?>

and this code on the client side:

        $.ajax({

            type : 'POST',
            url : 'php/general.ajax/header_search.php',

            //async : false,
            //cache : false,
            dataType : 'json',
            data: {
                keyword : sb_keyword
            },
            success : function(data) {

                var hs_hits = 0;

                var hs_row_nr = 1;
                var hs_results = "<div class='sb_spacing'></div><div id='sb_rows_cont'>";                   

                if (data != null) {

                    $.each(data, function(index, arr) {

                        hs_hits++;

                        if (arr['user_quarter_name'] != "") {

                            var quarter_text = "&nbsp;&nbsp;-&nbsp;&nbsp;" + arr['user_quarter_name'];

                        }
                        else {
                            var quarter_text = "";
                        }

                        hs_results = hs_results + "<a class='search_links' href=profile.php?id=" + arr['user_id'] + "><div class='sbr_row' row_nr='" + hs_row_nr + "'><div class='sbr_imgFrame'><img src='images/user_48x48/" + arr['user_tmb'] + "' alt=''></div><div class='sbr_name'>" + arr['user_fullname'].replace(regexp_hs_user_fullname, '<span>$&</span>') + "</div><div class='sbr_area'>" + arr['user_area_name'] + "</div><div class='sbr_area'>" + arr['user_city_name'] + quarter_text + "</div></div></a>";

                        hs_row_nr++;                        

                    });                     

                }

                if (hs_hits > 0) {

                    hs_results = hs_results + "</div><div class='sb_spacing'></div><a class='search_links' href='search.php?name=" + sb_keyword + "'><div id='sbr_botttom'>Se flere resultater for <span class='gay'>" + sb_keyword + "</span></div></a>";

                    $("#sb_results").html(hs_results).show();

                    searchSet = 1;
                    total_rows = hs_hits;

                    $("#sb_rows_cont > a:first .sbr_row").addClass('sbr_row_act');

                    on_a = $("#sb_rows_cont > a:first");
                    first_a = on_a;
                    last_a = $("#sb_rows_cont > a:last");
                    sb_url = $(on_a).attr('href');

                    search_navigator_init();                    

                }
                else {

                    $("#sb_results").hide();
                    searchSet = 0;                      

                }

            },
            error : function() {
                alert("ajax error");
            }
        });

one problem tho, if the query gives 0 results, and the each function tries to run on the client side my js code stops working..

so i was wondering what i could do here.

how can i retrieve the amount of hits from the server side, before i run the each loop?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-22T19:49:45+00:00Added an answer on May 22, 2026 at 7:49 pm

    You’re instantiating $rsl in the middle of a loop (implicitly), but you aren’t entering the loop unless you have at least one entry.

    Instantiate $rsl up above your while loop:

    ...
    $i = 0;
    $rsl = array();
    while ($userInfo = mysql_fetch_array($query)) {
    ...
    

    And now when you encode it, it is an empty array instead of null. This will also save your HTTP error_log, and generally be happier. : )

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have this code <?php session_start(); if (isset($_GET[cmd])) $cmd = $_GET[cmd]; else die(You should
I have this code in jQuery, that I want to reimplement with the prototype
I have this code: chars = #some list try: indx = chars.index(chars) except ValueError:
I have this code that performs an ajax call and loads the results into
I have this code #include <iostream> using namespace std; int main(int argc,char **argv) {
I have this code: CCalcArchive::CCalcArchive() : m_calcMap() { } m_calcMap is defined as this:
I have this code: myVariable which I want to change into trace(myVariable: + myVariable);
I have this code while($row = mysql_fetch_row($result)) { echo '<tr>'; $pk = $row[0]['ARTICLE_NO']; foreach($row
I have this code, which works fine, but I would like to be able
I have this code :- using (System.Security.Cryptography.SHA256 sha2 = new System.Security.Cryptography.SHA256Managed()) { .. }

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.