We help IT Professionals succeed at work.

How to export all my data in to a json array

armasmike
armasmike asked
on
130 Views
Last Modified: 2018-11-27
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 ?
Comment
Watch Question

Author

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

Consultant
CERTIFIED EXPERT
Commented:
This one is on us!
(Get your first solution completely free - no credit card required)
UNLOCK SOLUTION

Author

Commented:
That worked great !

Author

Commented:
Well that's only getting the info from 1 query I have two query's
I have a row3 and row2

Author

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

Author

Commented:
it doesn't like it if I do

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

Open in new window

Author

Commented:
I got it working
Unlock the solution to this question.
Join our community and discover your potential

Experts Exchange is the only place where you can interact directly with leading experts in the technology field. Become a member today and access the collective knowledge of thousands of technology experts.

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

OR

Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.