logo
Tags down

shadow

php create array from database


By : Toren
Date : May 03 2020, 09:32 AM

I trying to create exactly same array from database data which I am getting from while loop which will be passed to some other function and it does not accept anything else.

When i pass this data manually it works fine so it should be exactly same.

$putArray7 =array
(

      //  "title" => "Test Product " ,
      //  "body_html" => "test description" ,
        "images" => array
        (
        array(
              "id" => "6800163209265",
              "attachment" => "$attachment_base64",
        ),
        array(
              "id" => "6800163438641",
              "attachment" => "$attachment_base64",
        ),
        array(
              "id" => "6800164880433",
              "attachment" => "$attachment_base64",
        ),

 )

   );

What i tried:

  $response99 = array();
  $response_final = array();
// data from mysql starts here 

while($row = mysqli_fetch_assoc($res))

 {
      $response99[] = ['id'=>$id_img_id .',', 
  'attachment'=>$attachment_base64];

   }

Now tried to recreate whole array here:

// did not work 

     $response_final[] = ['title'=>"Test Product 53","body_html" => "test description" , 'images'=>$response99];

Tried this:

    $response_final[] = ['title'=>"Test Product 53","body_html" => "test description" , 'images'=>[$response99]];

This one also did not work:

Tried several other ways. Any help will be great.

Want to generate exactly like $putArray7.

Answer :

To Fix it , Do it like this:

$response99 = array();
$response_final = array();
while($row = mysqli_fetch_assoc($res)){
    $a = array();
    $a['id'] = $row['id'];
    $a['attachment'] = $row['attachment'];
    $response99[] = $a;
}
$response_final = array(
    'title' => "Test Product 53",
    'body_html' => "test description" ,
    'images' => $response99
);


Share : facebook icon twitter icon
Related Posts Related Posts :
  • clear array after form submit
  • pass url variable to javascript
  • access data using api
  • div position fixed css
  • add horizontal line between two div
  • disable toggle button css
  • css fixed line height
  • background image not working
  • table cell border
  • text line break css
  • overlay div on div
  • text direction rtl css
  • javascript convert string to an object
  • bind inner div click to outer div
  • jquery ajax oncomplete
  • how to use promise in for loop
  • jquery get element using variable
  • javascript send textbox value
  • pass div class content to another class or id
  • css new line after element
  • css calc not working properly
  • link disabled jquery
  • sql join table to subquery
  • MS Access SQL Issue with OR AND Operators
  • set textarea value using php
  • php merge two arrays into one
  • php form with google captcha
  • update current row in php
  • php date format mysql
  • mysql pdo select query
  • php function return an array
  • PHP mysqldump database to sql file
  • display image query
  • php create array using foreach loop
  • associative array php
  • group_concat in mysql laravel
  • php array_push empty
  • mysql on update cascade not working
  • pdo insert prepared statement
  • mysql insert ignore vs on duplicate key
  • mysql insert into existing row
  • mysql multi insert query
  • mysql group by show all rows
  • php change profile image
  • combine multiple arrays into one array php
  • how to sum values in an array
  • how to get sum of the total time
  • How to Create Facebook live stream without notification using API ?
  • on button click make div visible
  • css affect another element on hover
  • shadow
    Privacy Policy - Terms - Contact Us © bighow.org