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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T08:56:30+00:00 2026-06-05T08:56:30+00:00

I have this php code. As you can see i query a mysql database

  • 0

I have this php code. As you can see i query a mysql database through a function showallevents. I return a the $result to the $event variable. With the while loop i assign the values that i get from event to a response array and every time the loop happens the rows are stored in the data array. Surely i am failing somewhere because despite i am getting a correct number of responses all the values that i get at json are “null”. Also it tells me something about JSONarray cannot be converted to jsonobject

 if (isset($_POST['tag']) && $_POST['tag'] != '') 
 {
// get tag
$tag = $_POST['tag'];

// include db handler
require_once 'include/DB_Functions.php';
$db = new DB_Functions();

// response Array
$response = array("tag" => $tag, "success" => 0, "error" => 0);

// check for tag type
if ($tag == 'showallevents') 
{
    // Request type is show all events
    // show all events
    $event = $db->showallevents();
    if ($event != false)
    {
    $data = array();
    while($row = mysql_fetch_assoc($event)) 
        {
        $response["success"] = 1;
        $response["uid"] = $event["uid"];
        $response["event"]["date"] = $event["date"];
        $response["event"]["hours"] = $event["hours"];
        $response["event"]["store_name"] = $event["store_name"];
        $response["event"]["event_information"] = $event["event_information"];
        $response["event"]["event_type"] = $event["event_type"];
        $response["event"]["Phone"] = $event["Phone"];
        $response["event"]["address"] = $event["address"];
        $response["event"]["created_at"] = $event["created_at"];
        $response["event"]["updated_at"] = $event["updated_at"];
        $data[]=$response;

        }
        echo json_encode($data);            
    }
    else 
    {
        // event not found
        // echo json with error = 1
        $response["error"] = 1;
        $response["error_msg"] = "Events not found";
        echo json_encode($response);
    }
}
  else 
 { 
echo "Access Denied"; 
 }
}
?>

the DB_Functions.php

     <?php

    class DB_Functions 
   {

private $db;

//put your code here
// constructor
function __construct() 
{
    require_once 'DB_Connect.php';
    // connecting to database
    $this->db = new DB_Connect();
    $this->db->connect();
}

// destructor
function __destruct()
{

}


/**
 * Select all events that are after yesterday.
 */
public function showallevents()
{
   $result = mysql_query("SELECT * FROM events WHERE date >= CURDATE()");
   return($result);
   }

   }

  ?>

ok the code that helped me put all data into an array was this

            $data = array();
            while($row = mysql_fetch_assoc($event)) 
        {
        $response["success"] = 1;
        $response["event"]= $row;
        $data[]=$response;
        }
        echo json_encode($data);
  • 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-05T08:56:31+00:00Added an answer on June 5, 2026 at 8:56 am

    You’ve merged two independent pieces of code and wound up with a mess whose result is unclear.

    You can create an associative array in two ways:

    $array = (key=>value, key2=>value2);
    

    You can also use:

    $array[key]=value;
    $array[key2]=value2;
    

    Note that both ‘key’ and ‘value’ are simply variables; you can use strings there, or pass in a variable from someplace else.

    When doing similar things, I use the following approach:

        $response["success"] = 1;
        $response["uid"] = $event["uid"];
        $response["event"]["date"] = $event["date"];
        $response["event"]["hours"] = $event["hours"];
        $response["event"]["store_name"] = $event["store_name"];
        $response["event"]["event_information"] = $event["event_information"];
        $response["event"]["event_type"] = $event["event_type"];
        $response["event"]["Phone"] = $event["Phone"];
        $response["event"]["address"] = $event["address"];
        $response["event"]["created_at"] = $event["created_at"];
        $response["event"]["updated_at"] = $event["updated_at"];
        $data[]=$response;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

i have this PHP code, and a DataBase with Question, answer1, answer2, Question_id well,
I have this piece of php - mysql code: When a user tagged in
This is my php code (I already have a connection to the db): $result
This is the PHP code I have. function decrypt($s_input, $s_key, $s_iv) { $s_decrypted =
I have this PHP code: $result = mysql_query(SELECT distinct om_quote_no from `porders` order by
Okay. I have this code on my site: <?php session_start(); include database.php; include bruger.php;
I have a mysql database and php+js+jquery pages in my webpage. In this example
I have this php code $jsonArray = array(); $sql = SELECT ID,CLIENT FROM PLD_SERVERS;
I have this PHP code in a loop for every post on the admin
i have this php code and keep on getting errors upon fixing each error.

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.