Link to home
Start Free TrialLog in
Avatar of armasmike
armasmike

asked on

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 ?
Avatar of armasmike
armasmike

ASKER

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

ASKER CERTIFIED SOLUTION
Avatar of gr8gonzo
gr8gonzo
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
That worked great !
Well that's only getting the info from 1 query I have two query's
I have a row3 and row2
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
it doesn't like it if I do

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

Open in new window

I got it working