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

  • Home
  • SEARCH
  • 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 6541267
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T11:05:01+00:00 2026-05-25T11:05:01+00:00

Hi guys I´m new at stackoverflow and also new at Jquery Well hope I

  • 0

Hi guys I´m new at stackoverflow and also new at Jquery

Well hope I can make myself understandable. Here is what I want: I have made a query to my MySQL db, using a class with PHP

public function User($id) {
    $this->connect_db_web($conn);
    $sql = mysql_query("SELECT * FROM users WHERE id='".$id."'");
    while ($values = mysql_fetch_array($sql)) {
        $arr[]=array(
        'id'=>$values['idUsers'],
        'name'=>$values['name'],
        'name2'=>$values['name2'],
        'lname'=>$values['lname'],
        'lname2'=>$values['lname2'],
        'email'=>$values['email'],
        'phone'=>$values['phone'],
        'address'=>$values['address'],
        'bday'=>$values['bday'],
        'password'=>$values['password']
        );
    }
    echo '{"user":'.json_encode($arr).'}';
}

Then I have a php code where I call this function

$name = $user->User($id);

I think this works ok (if I´m wrong please help). Now what I´m really trying to do is getting the values from the JSON array into specific divs, example:

$.getJSON("user.php",function(data){
$.each(data.user, function(i,user){
    name = user.name;
    $(name).appendTo('#getname');
});
}); 

And inside my HML i Have a <p id="getname"></p>wich is the tag I want the value to be displayed

But no value is displayed, why?, what am I doing wrong?

Thanks for the help I apreciate it

  • 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-25T11:05:03+00:00Added an answer on May 25, 2026 at 11:05 am

    probably safer to do like this:

    echo json_encode(array("user" => $arr));
    

    on the other end you would receive an object which, I would suggest iterating like this:

    var k;

    for (k in data.user){
         $("#getname").append($("<span></span>").html(data.user[k].name));
    } 
    

    Given that you are fetching information for one user only, following I would suggest

    $id = (int) $_GET["id"]; // or wherever you get it from.
    if ($r = $db->mysql_fetch_assoc()){
        $response = array(
            "name" => $r["name"];
        );
        echo json_encode($response);
    } else {
        echo json_encode(array("error" => "Could not get name for user " . $id));
    }
    

    Then, on front-end, all you need to do is:

    if (typeof(data.name) != "undefined"){
        $("#getname").html(data.name);
    } else if (typeof(data.error) != "undefined"){
        $("#getname").html(data.error); //or handle otherwise
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Guys i am very new to jQuery. I have started using the auto complete
Hey guys I have what should be a simple question, but I am new
Frequent visitor but first post here on StackOverflow, I'm hoping that you guys might
Guys I'm new to xml in Java. I have the following task. I need
Hi guys i am new to Sitecore and asp.net and iis. I have installed
Hi guys am new to puppet and I want to execute the following command
hey guys here at stackoverflow.com I'm a student and developing a small todo app
Hey guys.I'm new to android and with the help of stackoverflow I somehow managed
Guys, I opened this question (I hope could help some others) but reading stackoverflow
I'm relatively new to C (and completely new to StackOverflow - hey guys!), and

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.