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 8018063
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T21:01:51+00:00 2026-06-04T21:01:51+00:00

I am trying to return all selected data from mysql table. What I want

  • 0

I am trying to return all selected data from mysql table. What I want is to return data in an array so that I will display that as json data. I acheived following so far but I do not know how ca I return that mysql data.

public function getHome() {
    $result = mysql_query("SELECT * FROM places") or die(mysql_error());
    // check for result
    $no_of_rows = mysql_num_rows($result);
    if ($no_of_rows > 0) {
        while($row = mysql_fetch_array($result)) {
            $data[] = $row;
        }
        return $data;
    } else {
        // user not found
        return false;
    }
}

here where I am calling this method

if($db->getHome()) {
        $data = $db->getHome();
        $response['success'] = 1;
        $response['uid'] = $data['uid'];
        $response['name'] = $data['name'];
        $response['profile_photo'] = $data['profile_photo_path'];
        $response['places']['place_photo'] = $data['place_photo_path'];
        $response['places']['created_at'] = $data['created_at'];
        echo json_encode($response);
    } else {
        echo "bye";
    }

here is what it echos

{"tag":"home","success":1,"error":0,"uid":null,"name":null,"profile_photo":null,"places":{"place_photo":null,"created_at":null}}
  • 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-06-04T21:01:53+00:00Added an answer on June 4, 2026 at 9:01 pm

    You need to define $data as an array first, besides that your code looks fine.

    $data = array();
    

    As you are, potentially, returning multiple rows you should be doing something like:

    $data = $db->getHome(); // There's no need to call this twice
    if($data) {
      foreach($data as $place) {
        // Do what you need to do with each place here
      }
    }
    

    Take a look at to see the contents of your $data print_r($data);

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

Sidebar

Related Questions

I am trying to use Linq2Sql to return all rows that contain values from
I'm trying to write a function that will return all the available cars for
Iam trying to return json data from codeigniter view. but my code is not
I'm processing a large chunk of data, and am trying to return all the
Trying to return a DB resultset as an array in my DAO: I want
I have a mysql table containing news data and categories and i'm trying to
I'm trying to fetch some data from a database. I want to select an
I am trying to grab data a user selected from a drop down menu.
All, I am trying to use predicates to bring back a search return, giving
Iam trying to return data ( the stored exercises information : Name , period

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.