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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T07:53:42+00:00 2026-06-17T07:53:42+00:00

I create php file to get all task from database but when I enter

  • 0

I create php file to get all task from database but when I enter the url “localhost/evisiting/get_all_task.php” in browser it get all task details but with null data in each row. However I populate my database table. Kindly guide how can i get these values from database not the null values..

Its my php file:

    get_all_task.php
<?php

/*
 * Following code will list all the tasks
 */

// array for JSON response
$response = array();

// include db connect class
require_once __DIR__ . '/db_connect.php';

// connecting to db
$db = new DB_CONNECT();

// get all task from my_task table
$result = mysql_query("SELECT *FROM my_task") or die(mysql_error());

// check for empty result
if (mysql_num_rows($result) > 0) {
    // looping through all results
    // task node
    $response["my_task"] = array();

    while ($row = mysql_fetch_array($result)) {
        // temp user array
            $my_task = array();
            $my_task["cid"] = $result["cid"];
            $my_task["cus_name"] = $result["cus_name"];
            $my_task["contact_number"] = $result["contact_number"];
            $my_task["ticket_no"] = $result["ticket_no"];
            $my_task["task_detail"] = $result["task_detail"];

        // push single task into final response array
        array_push($response["my_task"], $my_task);
    }
    // success
    $response["success"] = 1;

    // echoing JSON response
    echo json_encode($response);
} else {
    // no task found
    $response["success"] = 0;
    $response["message"] = "No task found";

    // echo no users JSON
    echo json_encode($response);
}
?>
  • 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-17T07:53:43+00:00Added an answer on June 17, 2026 at 7:53 am

    You’re using the wrong variable inside your while() loop. $result is your query result handle, NOT the row you fetched:

            $my_task["cid"] = $result["cid"];
                              ^^^^^^^--- should be $row
    

    As well, you’re spitting out a lot of code to fetch individual fields when you could simply have this:

    $result = mysql_query("SELECT cid, cus_name, contact_number, .... FROM my_task") or die(mysql_error());
    $response['my_task'] = array();
    while($row = mysql_fetch_assoc($result)) {
       $response['my_task'][] = $row;
    }
    

    exact same end-result, but far less repetition of all those field names – if you want to add a new field into this result, you simply at it to the SELECT statement, and the rest of the code handles it automatically. If you need to change the field name in the $response array, simply alias it in the query.

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

Sidebar

Related Questions

I'm trying to create a kind of file generator in Php. Basically, it get
I am trying to create a php file that adds a user and create
Is it possible to create a PHP file that runs once with no errors
I am trying to create a php file that would scan a directory, make
I am trying to create a PHP file to upload images to my website.
How can I create a simple PHP file, which will retrieve the HTML and
Possible Duplicate: PHP create a file without fopen I want to create a file
How can I create custom variable in helper.php file set it right here and
I'm using a function in a php file to create some li and some
Having the following url I get all the pages I admin and applications I

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.