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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T03:45:21+00:00 2026-06-12T03:45:21+00:00

I have a PHP MySQL fetch while loop as shown below in my script:

  • 0

I have a PHP MySQL fetch while loop as shown below in my script:

$result2211 = mysql_query("select * from products where is_config = 'yes' ");
while($row2211 = mysql_fetch_assoc($result2211))
{
   $sn = $row2211['sn'];
   $allparrentselectq = mysql_query("SELECT * FROM parrentpro where parrentsn = $sn");
   while($allparrentselect = mysql_fetch_assoc($allparrentselectq))
   {
       $childarr = unserialize($allparrentselect['childsn']);
       $subpro  = '{"catname":"'.$allparrentselect['childname'].'",';
       $i = 0;
       foreach($childarr as $childarr):
           $subpro .= '"Pro'.$i++.'":"'.$childarr.'",';
       endforeach;
       $subpro1[] = substr($subpro, 0, -1)."}";
       $subproa = "[".implode(",",$subpro1)."]";
   }
   $prodObj2 = new ProductDetails();
   $prodObj2->productname = $row2211['productname'];
   $prodObj2->price = $row2211['productprice'];
   $prodObj2->discount = $row2211['discount'];
   $prodObj2->discountprice = $row2211['discountprice'];
   $prodObj2->imageURL = $row2211['productimageurl'];
   $prodObj2->category = $row2211['productcat'];
   $prodObj2->configurablepone = $subproa;
   $prodObj2->configurable = 'yes';
   array_push($totArr, $prodObj2);
}

In that I have a problem. I get the result as like below (JSON):

[
    {
        "productname":"Veg.Pizaa",
        "price":"350",
        "discount":"",
        "discountprice":"350",
        "imageURL":"http:\/\/farm8.staticflickr.com\/7154\/6694188161_9ee692d854_s.jpg",
        "category":"Pizaa",
        "configurablepone":[{"catname":"Extra","Pro0":"Extra 25g Cheese","Pro1":"Extra 75g Cheese"},"catname":"Nuts","Pro0":"Almonds","Pro1":"Peanuts","Pro2":"Pistachios"}],
        "configurable":"yes"
    },
    {
        "productname":"Core i7 Pc",
        "price":"48000",
        "discount":"2",
        "discountprice":"47040",
        "imageURL":"http:\/\/www.4to40.com\/images\/science\/Basic_Computer_Parts\/Computer.jpg",
        "category":"Pc",
        "configurablepone":[{"catname":"Extra","Pro0":"Extra 25g Cheese","Pro1":"Extra 75g Cheese"},{"catname":"Nuts","Pro0":"Almonds","Pro1":"Peanuts","Pro2":"Pistachios"},{"catname":"Harddisk","Pro0":"Segate 500Gb","Pro1":"Samsung 250Gb"},{"catname":"Ram","Pro0":"8Gb Ram","Pro1":"4Gb Ram","Pro2":"2Gb Ram"}],
        "configurable":"yes"
    }
]

But I need the result as like below:

[
    {
        "productname":"Veg.Pizaa",
        "price":"350",
        "discount":"",
        "discountprice":"350",
        "imageURL":"http:\/\/farm8.staticflickr.com\/7154\/6694188161_9ee692d854_s.jpg",
        "category":"Pizaa",
        "configurablepone":[{"catname":"Extra","Pro0":"Extra 25g Cheese","Pro1":"Extra 75g Cheese"},"catname":"Nuts","Pro0":"Almonds","Pro1":"Peanuts","Pro2":"Pistachios"}],
        "configurable":"yes"
    },
    {
        "productname":"Core i7 Pc",
        "price":"48000",
        "discount":"2",
        "discountprice":"47040",
        "imageURL":"http:\/\/www.4to40.com\/images\/science\/Basic_Computer_Parts\/Computer.jpg",
        "category":"Pc",
        "configurablepone":[{"catname":"Harddisk","Pro0":"Segate 500Gb","Pro1":"Samsung 250Gb"},{"catname":"Ram","Pro0":"8Gb Ram","Pro1":"4Gb Ram","Pro2":"2Gb Ram"}],
        "configurable":"yes"
    }
]

As you can see configurablepone JSON is getting repeated for every loop so I am getting the value of the first product in second product also but I need to seperate like below:

First Product As Like Below

"configurablepone":[{"catname":"Extra","Pro0":"Extra 25g Cheese","Pro1":"Extra 75g Cheese"},{"catname":"Nuts","Pro0":"Almonds","Pro1":"Peanuts","Pro2":"Pistachios"}]

Second Product As Like Below

"configurablepone":[{"catname":"Harddisk","Pro0":"Segate 500Gb","Pro1":"Samsung 250Gb"},{"catname":"Ram","Pro0":"8Gb Ram","Pro1":"4Gb Ram","Pro2":"2Gb Ram"}]

I have tried changing the loop but I haven’t found any solutions. Kindly help me to solve this.

  • 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-12T03:45:22+00:00Added an answer on June 12, 2026 at 3:45 am

    Just Use unset($subpro1); after the array_push($totArr, $prodObj2);.
    Below Is An example Source
    Try This One This May Work

    $result2211 = mysql_query("select * from products where is_config = 'yes' ");
    while($row2211 = mysql_fetch_assoc($result2211))
    {
       $sn = $row2211['sn'];
       $allparrentselectq = mysql_query("SELECT * FROM parrentpro where parrentsn = $sn");
       while($allparrentselect = mysql_fetch_assoc($allparrentselectq))
       {
           $childarr = unserialize($allparrentselect['childsn']);
           $subpro  = '{"catname":"'.$allparrentselect['childname'].'",';
           $i = 0;
           foreach($childarr as $childarr):
               $subpro .= '"Pro'.$i++.'":"'.$childarr.'",';
           endforeach;
           $subpro1[] = substr($subpro, 0, -1)."}";
           $subproa = "[".implode(",",$subpro1)."]";
       }
       $prodObj2 = new ProductDetails();
       $prodObj2->productname = $row2211['productname'];
       $prodObj2->price = $row2211['productprice'];
       $prodObj2->discount = $row2211['discount'];
       $prodObj2->discountprice = $row2211['discountprice'];
       $prodObj2->imageURL = $row2211['productimageurl'];
       $prodObj2->category = $row2211['productcat'];
       $prodObj2->configurablepone = $subproa;
       $prodObj2->configurable = 'yes';
       array_push($totArr, $prodObj2);
       unset($subpro1);
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a problem with my php/mysql script. It should only output the while
I have a while loop that shows the results from a select query. Then
I'm having a simple select statement using php-mysql and I have this script to
I have PHP script works without problems, like this : while($row4 = mysql_fetch_array($result4)) {
I have the following code: (query added) $weight_table = mysql_query (SELECT * FROM .$prefix.weight
I have a table of php with while loop to show the records. I
I have some PHP script querying a mysql database and echoing out a piece
I have the following PHP that creates some JSON from a MySQL query. This
I have a page where I am using a PHP while loop to echo
I have php mysql application and i want the phone numbers be saved in

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.