How to export all my data in to a json array

How to export all my data in to a json array

Here is my code

<?php
ini_set('display_errors', TRUE);
error_reporting(E_ALL);


if(isset($_POST['submit']))
{


$UsrWorkOrder = $_POST['Work_Order'];


//db connect info
include 'conn.php';
//Where the query are stored 
include 'Query.php';




$result_Vis = odbc_exec($conn_Vis,$sql_Vis);  // Get Data From Result
    while($row2 = odbc_fetch_array($result_Vis))
    {
//Store the data in the new array

 

            $result_cor1db01_2 = odbc_exec($conn_cor1db01_2,$sql_cor1db01_2);  // Get Data From Result

            while($row3 = odbc_fetch_array($result_cor1db01_2))
            {







//This stores the data 
            	$Barcode = $row3["Work Order No"]."-". $row3["Serial No"];
       			$part = $row2["PART_X"];
        		$DESCR = $row2["DESCR_X"];
            	$Cable_Length = $row3["ValueInches"];
            	$MFG = $row3["Work Order No"]."-". $row3["Serial No"];
            	$Test_A = number_format($row3["Value1"],2);
            	$Test_B = number_format($row3["Value2"],2);



                    Echo "<br><br><img src=barcode.php?codetype=Code128B&size=80&text=".$row3["Work Order No"]."-". $row3["Serial No"] ." />";
                    Echo "<br>".$row3["Work Order No"]."-". $row3["Serial No"]."<br>";
                    Echo "Part Number: ".$part."<br>";
                    Echo "Description: " .$DESCR."<br>";
                    Echo "Mfg Lot Number: " .$row3["Work Order No"]."-". $row3["Serial No"]."<br>";
                    Echo "Cable Length: ". $row3["ValueInches"]."<br>";
                    Echo "Test Results: ".substr($row3["SS1"], -1)." " .number_format($row3["Value1"],2)."<br>";
                    Echo "Test Results: ".substr($row3["SS2"], -1)." " .number_format($row3["Value2"],2)."<br>";




            }

    }

    
odbc_close($conn_cor1db01_2);
odbc_close($conn_Vis);

}

?>

Open in new window


How can I put all the data it gets in to a json array. I have attached a file of the output data. What-i-want-it-to-be.xlsx

How can I put this in a json array ?
armasmikeAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

armasmikeAuthor Commented:
I think I got it working with this

$posts = array();
$J_Barcode = $row3["Work Order No"]."-". $row3["Serial No"];
    $posts []= array (
        'Barcode ' => $J_Barcode );

Open in new window

gr8gonzoConsultantCommented:
You use json_encode() to turn an array into JSON. If you want an array containing all the rows, you would first add a container to store your rows BEFORE your loop:
while($row3 = odbc_fetch_array($result_cor1db01_2))
{

Open in new window

to:
$rows = array(); // <-- Container
while($row3 = odbc_fetch_array($result_cor1db01_2))
{
$rows[] = $row3; // <-- Add row to container

Open in new window


Then after your loop:
            }
    echo json_encode($rows); // Convert your $rows to a JSON string and display it
    }
    
odbc_close($conn_cor1db01_2);
odbc_close($conn_Vis);
}
?>

Open in new window


This also presumes the inner loop is the one where you want the container.

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
armasmikeAuthor Commented:
That worked great !
Big Business Goals? Which KPIs Will Help You

The most successful MSPs rely on metrics – known as key performance indicators (KPIs) – for making informed decisions that help their businesses thrive, rather than just survive. This eBook provides an overview of the most important KPIs used by top MSPs.

armasmikeAuthor Commented:
Well that's only getting the info from 1 query I have two query's
I have a row3 and row2
armasmikeAuthor Commented:
this is all the info I need to go in the json array

$Barcode = $row3["Work Order No"]."-". $row3["Serial No"];
       			$part = $row2["PART_X"];
        		$DESCR = $row2["DESCR_X"];
            	$Cable_Length = $row3["ValueInches"];
            	$MFG = $row3["Work Order No"]."-". $row3["Serial No"];
            	$Test_A = number_format($row3["Value1"],2);
            	$Test_B = number_format($row3["Value2"],2);

Open in new window




$part = $row2["PART_X"];
$DESCR = $row2["DESCR_X"];

Open in new window



are the only 2 from other db server
armasmikeAuthor Commented:
it doesn't like it if I do

$json []= "barcode" => $Barcode = $row3["Work Order No"]."-". $row3["Serial No"]

Open in new window

armasmikeAuthor Commented:
I got it working
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
PHP

From novice to tech pro — start learning today.