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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T18:26:22+00:00 2026-06-11T18:26:22+00:00

I have a PHP page encoding a MySQL select into JSON. I would like

  • 0

I have a PHP page encoding a MySQL select into JSON.
I would like to add a “Status value” as the first object of my array.

PHP code

{
//CREATE USER UNKNOWN ARRAY RESULT
$Statusresult = mysql_query("SELECT TEXT_KEY, TEXT_VALUE FROM T_TEXTS WHERE TEXT_KEY = 'USER_FAILED' ") or die(mysql_error());
$Statusrows = array();
while($s = mysql_fetch_assoc($Statusresult)) 
{
    $Statusrows[] = $s;
}
print json_encode($Statusrows);

}

This results is:

{
"TEXT_KEY" = "USER_FAILED";
"TEXT_VALUE" = "UNKNOWN USER";

}

I would like to add the first object manual, to have the result look like this:

        {
    "STATUS" = "1";
    "TEXT_KEY" = "USER_FAILED";
    "TEXT_VALUE" = "UNKNOWN USER";
}

How can I do this ?

I have tried this approach, but somehow there is an error…

{
    //CREATE USER UNKNOWN ARRAY RESULT
    $Statusresult = mysql_query("SELECT TEXT_KEY, TEXT_VALUE FROM T_TEXTS WHERE TEXT_KEY = 'USER_FAILED' ") or die(mysql_error());
    $Statusrows = array();
    $Statusrows = { "STATUS" => "1" };
    while($s = mysql_fetch_assoc($Statusresult)) 
    {
    //  $Statusrows[] = $s;
        array_push($Statusrows, $s);    
    }
    print json_encode($Statusrows);
}
  • 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-11T18:26:23+00:00Added an answer on June 11, 2026 at 6:26 pm

    Add a virtual column on it,

    SELECT '"1"' AS `STATUS`, TEXT_KEY, TEXT_VALUE 
    FROM T_TEXTS 
    WHERE TEXT_KEY = 'USER_FAILED'
    

    SQLFiddle Demo

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

Sidebar

Related Questions

I have a MySQL database with tables in ucs2_slovenian_ci encoding. I would like to
i have a php page that redirects (if successful) to another php page like
I have this PHP page where the user can select and un-select items. The
I have a PHP page, in Wordpress. When I add a inline Thickbox to
I have got mysql database in utf8_general_ci and php page with utf-8 charset. Why
I have a problem with encoding of PHP and Mysql. The encoding of the
I have a VPS (Debian, Apache, MySQL, PHP) I want to force the encoding
I have a PHP page where i want to open a file on a
I have a PHP page that loads external content using other PHP files. I'm
I have a php page with a dropdown list that is populated by a

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.