12 Replies - 425 Views - Last Post: 11 November 2019 - 06:13 PM Rate Topic: -----

#1 Bobby_Bubbles   User is offline

  • D.I.C Regular

Reputation: 1
  • View blog
  • Posts: 339
  • Joined: 13-March 18

parsing JSON but cant pull info

Posted 05 November 2019 - 12:07 PM

These are the kinds of json i have to pull and extra data from.

[{"item_id":"28","row":"","merchant_id":"1","discount":"","currentController":"store","category_id":"4","with_size":"2","price":"45|Single|7","qty":"1","notes":"","yii_session_token":"9847090ac90685a11a6412e473c4face","YII_CSRF_TOKEN":"2923281a9a02b559eff5d3b5f324e6f2702135dc","two_flavors":"","non_taxable":"2","sub_item":""},{"item_id":"29","row":"","merchant_id":"1","discount":"","currentController":"store","category_id":"4","with_size":"2","price":"45|Single|7","qty":"1","notes":"","yii_session_token":"9847090ac90685a11a6412e473c4face","YII_CSRF_TOKEN":"2923281a9a02b559eff5d3b5f324e6f2702135dc","two_flavors":"","non_taxable":"2","sub_item":""}]



{"1":{"item_id":"28","row":"","merchant_id":"1","discount":"","currentController":"store","category_id":"4","with_size":"2","price":"300|Pack of 7|8","qty":"1","notes":"","yii_session_token":"f3d29e7d680b33e0f6c2c17e6c53e4ae","YII_CSRF_TOKEN":"8ec9754fea5ff1665436281b4f155ba27b7d2b0c","two_flavors":"","non_taxable":"2","sub_item":""}}



{"1":{"item_id":"24","row":"","merchant_id":"1","discount":"","currentController":"store","category_id":"1","price":"70|14g|6","qty":"1","notes":"","yii_session_token":"d9f5c44506fad4327a81f8e72979711c","YII_CSRF_TOKEN":"82098b6d862797d1d240b406ee80c93a803fa32d","two_flavors":"","non_taxable":"2","sub_item":""},"2":{"item_id":"13","row":"","merchant_id":"1","discount":"","currentController":"store","category_id":"3","price":"85|14g|6","qty":"1","notes":"","yii_session_token":"d9f5c44506fad4327a81f8e72979711c","YII_CSRF_TOKEN":"82098b6d862797d1d240b406ee80c93a803fa32d","two_flavors":"","non_taxable":"2","sub_item":""}}



As you can see from above the info being put into the db field is not very well done. nevertheless i have to deal with these possibilities.

This is what i got so far

$query = mysqli_query($conn,"SELECT order_id, json_details FROM mt_order WHERE status='Delivered' AND order_id='17'")or die(mysqli_error($conn));
				while($fet = mysqli_fetch_array($query)){
					$result = json_decode($fet['json_details']);
					echo '<pre>';
					print_r($result);
					echo '</pre>';
					//echo 'Result : '.$result[0];
					//echo 'Test : '.$result[0]['price'];
					if(sizeof($result) > 0){
						foreach($result AS $key=>$value){
							//echo $result[$key]['price'];
							//echo 'Key '.$result$[$key+1]['price'].'<br/>';
							//echo $key.'->'.$value['price'].'<br/>';
						}
					}else{
						echo 'test';
					}
				}



and this is the sample output for readability. This is the first JSON i posted.

Array
(
    [0] => stdClass Object
        (
            [item_id] => 28
            [row] => 
            [merchant_id] => 1
            [discount] => 
            [currentController] => store
            [category_id] => 4
            [with_size] => 2
            [price] => 45|Single|7
            [qty] => 1
            [notes] => 
            [yii_session_token] => 9847090ac90685a11a6412e473c4face
            [YII_CSRF_TOKEN] => 2923281a9a02b559eff5d3b5f324e6f2702135dc
            [two_flavors] => 
            [non_taxable] => 2
            [sub_item] => 
        )

    [1] => stdClass Object
        (
            [item_id] => 29
            [row] => 
            [merchant_id] => 1
            [discount] => 
            [currentController] => store
            [category_id] => 4
            [with_size] => 2
            [price] => 45|Single|7
            [qty] => 1
            [notes] => 
            [yii_session_token] => 9847090ac90685a11a6412e473c4face
            [YII_CSRF_TOKEN] => 2923281a9a02b559eff5d3b5f324e6f2702135dc
            [two_flavors] => 
            [non_taxable] => 2
            [sub_item] => 
        )

)



I really only want the price, qty and item_id but whenever i try to retrieve the information it says std cant be used as an array. i tried different ways but i cant figure it out.

Is This A Good Question/Topic? 0
  • +

Replies To: parsing JSON but cant pull info

#2 ArtificialSoldier   User is offline

  • D.I.C Lover
  • member icon

Reputation: 2494
  • View blog
  • Posts: 7,551
  • Joined: 15-January 14

Re: parsing JSON but cant pull info

Posted 05 November 2019 - 01:35 PM

$result[0]->item_id, etc. PHP is correct, an object is not an array.
Was This Post Helpful? 0
  • +
  • -

#3 Bobby_Bubbles   User is offline

  • D.I.C Regular

Reputation: 1
  • View blog
  • Posts: 339
  • Joined: 13-March 18

Re: parsing JSON but cant pull info

Posted 05 November 2019 - 01:40 PM

that doesnt work. i tried it.
Was This Post Helpful? 0
  • +
  • -

#4 ArtificialSoldier   User is offline

  • D.I.C Lover
  • member icon

Reputation: 2494
  • View blog
  • Posts: 7,551
  • Joined: 15-January 14

Re: parsing JSON but cant pull info

Posted 05 November 2019 - 02:50 PM

That works for the structure you showed.
Was This Post Helpful? 0
  • +
  • -

#5 Bobby_Bubbles   User is offline

  • D.I.C Regular

Reputation: 1
  • View blog
  • Posts: 339
  • Joined: 13-March 18

Re: parsing JSON but cant pull info

Posted 05 November 2019 - 03:50 PM

current working code

$query = mysqli_query($conn,"SELECT order_id, json_details FROM mt_order WHERE status='Delivered' AND order_id='18'")or die(mysqli_error($conn));
				while($fet = mysqli_fetch_array($query)){
					$result = json_decode($fet['json_details']);
					echo '<pre>';
					print_r($result);
					echo '</pre>';
					if(sizeof($result) > 0){
						foreach($result AS $key=>$value){
							echo $key.'<br/>';
							echo $result[$key]->item_id.'<br/>';
						}
					}else{
						echo 'test';
					}
				}



and it works for the following JSON

Array
(
    [0] => stdClass Object
        (
            [item_id] => 28
            [row] => 
            [merchant_id] => 1
            [discount] => 
            [currentController] => store
            [category_id] => 4
            [with_size] => 2
            [price] => 45|Single|7
            [qty] => 1
            [notes] => 
            [yii_session_token] => 9847090ac90685a11a6412e473c4face
            [YII_CSRF_TOKEN] => 2923281a9a02b559eff5d3b5f324e6f2702135dc
            [two_flavors] => 
            [non_taxable] => 2
            [sub_item] => 
        )

    [1] => stdClass Object
        (
            [item_id] => 29
            [row] => 
            [merchant_id] => 1
            [discount] => 
            [currentController] => store
            [category_id] => 4
            [with_size] => 2
            [price] => 45|Single|7
            [qty] => 1
            [notes] => 
            [yii_session_token] => 9847090ac90685a11a6412e473c4face
            [YII_CSRF_TOKEN] => 2923281a9a02b559eff5d3b5f324e6f2702135dc
            [two_flavors] => 
            [non_taxable] => 2
            [sub_item] => 
        )

)



but it doesnt work for other jsons such as these below.

stdClass Object
(
    [1] => stdClass Object
        (
            [item_id] => 28
            [row] => 
            [merchant_id] => 1
            [discount] => 
            [currentController] => store
            [category_id] => 4
            [with_size] => 2
            [price] => 300|Pack of 7|8
            [qty] => 1
            [notes] => 
            [yii_session_token] => f3d29e7d680b33e0f6c2c17e6c53e4ae
            [YII_CSRF_TOKEN] => 8ec9754fea5ff1665436281b4f155ba27b7d2b0c
            [two_flavors] => 
            [non_taxable] => 2
            [sub_item] => 
        )

)



or this

stdClass Object
(
    [1] => stdClass Object
        (
            [item_id] => 24
            [row] => 
            [merchant_id] => 1
            [discount] => 
            [currentController] => store
            [category_id] => 1
            [price] => 70|14g|6
            [qty] => 1
            [notes] => 
            [yii_session_token] => d9f5c44506fad4327a81f8e72979711c
            [YII_CSRF_TOKEN] => 82098b6d862797d1d240b406ee80c93a803fa32d
            [two_flavors] => 
            [non_taxable] => 2
            [sub_item] => 
        )

    [2] => stdClass Object
        (
            [item_id] => 13
            [row] => 
            [merchant_id] => 1
            [discount] => 
            [currentController] => store
            [category_id] => 3
            [price] => 85|14g|6
            [qty] => 1
            [notes] => 
            [yii_session_token] => d9f5c44506fad4327a81f8e72979711c
            [YII_CSRF_TOKEN] => 82098b6d862797d1d240b406ee80c93a803fa32d
            [two_flavors] => 
            [non_taxable] => 2
            [sub_item] => 
        )

)



I have to loop through all items in the json string. some are structured different. How can you distinguish the difference with the 2 jsons.
Was This Post Helpful? 0
  • +
  • -

#6 ArtificialSoldier   User is offline

  • D.I.C Lover
  • member icon

Reputation: 2494
  • View blog
  • Posts: 7,551
  • Joined: 15-January 14

Re: parsing JSON but cant pull info

Posted 05 November 2019 - 04:55 PM

I suppose you can use isset to check if various things are set, but this code isn't going to be pretty because your data is all messed up. If you can't normalize your data then that's going to be a problem trying to write the code to handle a bunch of different data formats. Ideally you wouldn't store a JSON string at all, you'd have fields in the database for each of those fields in the JSON objects.

Trying to access properties of an object where the property name is an integer means doing this:

$obj->{'1'}

or this:
$prop = 1;
echo $obj->$prop;


You can also use the second parameter of json_decode to say that you want an associate array returned instead of objects, maybe that will make things easier. It's still going to be a little weird if the numeric array keys have gaps, like if it starts at 1 instead of 0. That's why it's trying to make an object instead of an array, because arrays start at 0.
Was This Post Helpful? 0
  • +
  • -

#7 CTphpnwb   User is offline

  • D.I.C Lover
  • member icon

Reputation: 3826
  • View blog
  • Posts: 13,946
  • Joined: 08-August 08

Re: parsing JSON but cant pull info

Posted 05 November 2019 - 07:23 PM

You could just decode everything to an array.
$json = '{"1":{"item_id":"24","row":"","merchant_id":"1","discount":"","currentController":"store","category_id":"1","price":"70|14g|6","qty":"1","notes":"","yii_session_token":"d9f5c44506fad4327a81f8e72979711c","YII_CSRF_TOKEN":"82098b6d862797d1d240b406ee80c93a803fa32d","two_flavors":"","non_taxable":"2","sub_item":""},"2":{"item_id":"13","row":"","merchant_id":"1","discount":"","currentController":"store","category_id":"3","price":"85|14g|6","qty":"1","notes":"","yii_session_token":"d9f5c44506fad4327a81f8e72979711c","YII_CSRF_TOKEN":"82098b6d862797d1d240b406ee80c93a803fa32d","two_flavors":"","non_taxable":"2","sub_item":""}}';
$decoded = json_decode($json, true, 512, JSON_OBJECT_AS_ARRAY );
var_dump($decoded);


Was This Post Helpful? 0
  • +
  • -

#8 Bobby_Bubbles   User is offline

  • D.I.C Regular

Reputation: 1
  • View blog
  • Posts: 339
  • Joined: 13-March 18

Re: parsing JSON but cant pull info

Posted 08 November 2019 - 11:15 AM

im trying to fix up my code to be better suited for what i need and this is my current updated code.

$query = mysqli_query($conn,"SELECT order_id, json_details FROM mt_order WHERE status='Delivered' AND order_id<'25'")or die(mysqli_error($conn));
				$saleinv = array(1 => array(),2 => array());
				while($fet = mysqli_fetch_array($query)){
					$result = json_decode($fet['json_details'],true);
					echo 'Order ID : '.$fet['order_id'].'<br/>';
					echo '<pre>';
					print_r($result);
					echo '</pre>';
					foreach($result AS $key=>$value){
						list($mprice,$w,$unk) = explode('|', $value['price']);
						$w = str_replace("g","",$w);
						if($w == '1' || $w == 'Sinle'){
							array_push($saleinv[$value['merchant_id']][$value['item_id']]['Single'],array('price' => $mprice,'qty' => $value['qty']));
						}elseif($w == '7'){
							array_push($saleinv[$value['merchant_id']][$value['item_id']][$w],array('price' => $mprice,'qty' => $value['qty']));
						}elseif($w == '14'){
							array_push($saleinv[$value['merchant_id']][$value['item_id']][$w],array('price' => $mprice,'qty' => $value['qty']));
						}elseif($w == '28'){
							array_push($saleinv[$value['merchant_id']][$value['item_id']][$w],array('price' => $mprice,'qty' => $value['qty']));
						}
					}
				}
				echo '<pre>';
				print_r($saleinv);
				echo '</pre>';



and this is the output for it

Order ID : 17
Array
(
    [0] => Array
        (
            [item_id] => 28
            [row] => 
            [merchant_id] => 1
            [discount] => 
            [currentController] => store
            [category_id] => 4
            [with_size] => 2
            [price] => 45|Single|7
            [qty] => 1
            [notes] => 
            [yii_session_token] => 9847090ac90685a11a6412e473c4face
            [YII_CSRF_TOKEN] => 2923281a9a02b559eff5d3b5f324e6f2702135dc
            [two_flavors] => 
            [non_taxable] => 2
            [sub_item] => 
        )

    [1] => Array
        (
            [item_id] => 29
            [row] => 
            [merchant_id] => 1
            [discount] => 
            [currentController] => store
            [category_id] => 4
            [with_size] => 2
            [price] => 45|Single|7
            [qty] => 1
            [notes] => 
            [yii_session_token] => 9847090ac90685a11a6412e473c4face
            [YII_CSRF_TOKEN] => 2923281a9a02b559eff5d3b5f324e6f2702135dc
            [two_flavors] => 
            [non_taxable] => 2
            [sub_item] => 
        )

)

Warning: array_push() expects parameter 1 to be array, null given in ... on line 62

Warning: array_push() expects parameter 1 to be array, null given in ... on line 62
Order ID : 18
Array
(
    [1] => Array
        (
            [item_id] => 28
            [row] => 
            [merchant_id] => 1
            [discount] => 
            [currentController] => store
            [category_id] => 4
            [with_size] => 2
            [price] => 300|Pack of 7|8
            [qty] => 1
            [notes] => 
            [yii_session_token] => f3d29e7d680b33e0f6c2c17e6c53e4ae
            [YII_CSRF_TOKEN] => 8ec9754fea5ff1665436281b4f155ba27b7d2b0c
            [two_flavors] => 
            [non_taxable] => 2
            [sub_item] => 
        )

)
Order ID : 21
Array
(
    [0] => Array
        (
            [item_id] => 24
            [row] => 
            [merchant_id] => 1
            [discount] => 
            [currentController] => store
            [category_id] => 3
            [price] => 130|28g|5
            [qty] => 1
            [notes] => 
            [yii_session_token] => a4261b6afe7153d02b3b09c4289c2e82
            [YII_CSRF_TOKEN] => 0dafc9748ab9b5addbf26176b3a8d16237a140a8
            [two_flavors] => 
            [non_taxable] => 2
            [sub_item] => 
        )

)

Warning: array_push() expects parameter 1 to be array, null given in ... on line 68
Order ID : 22
Array
(
    [0] => Array
        (
            [item_id] => 22
            [row] => 
            [merchant_id] => 1
            [discount] => 
            [currentController] => store
            [category_id] => 3
            [price] => 140|28g|5
            [qty] => 1
            [notes] => 
            [yii_session_token] => b044de6469e607ae01beaa3acb467f06
            [YII_CSRF_TOKEN] => e39dea073a3f3066dfe80ea5fc170d0ca584f0ee
            [two_flavors] => 
            [non_taxable] => 2
            [sub_item] => 
        )

)

Warning: array_push() expects parameter 1 to be array, null given in ... on line 68
Order ID : 23
Array
(
    [0] => Array
        (
            [item_id] => 11
            [row] => 
            [merchant_id] => 1
            [discount] => 
            [currentController] => store
            [category_id] => 3
            [price] => 70|7g|4
            [qty] => 1
            [notes] => 
            [yii_session_token] => 7ef78c20d32e4bb876a3be5ac99587f3
            [YII_CSRF_TOKEN] => a51cce8f15984f5c001ddc62b602a38034ba8946
            [two_flavors] => 
            [non_taxable] => 2
            [sub_item] => 
        )

)

Warning: array_push() expects parameter 1 to be array, null given in ... on line 64
Order ID : 24
Array
(
    [0] => Array
        (
            [item_id] => 23
            [row] => 1
            [merchant_id] => 1
            [discount] => 
            [currentController] => store
            [category_id] => 3
            [with_size] => 2
            [price] => 50|7g|4
            [qty] => 1
            [notes] => 
            [yii_session_token] => ed32546fbfe85a98027f63bf45871779
            [YII_CSRF_TOKEN] => 1588d69d9438b5ee52ddfda4c948dd1c3316a149
            [two_flavors] => 
            [non_taxable] => 2
        )

)

Warning: array_push() expects parameter 1 to be array, null given in ... on line 64
Array
(
    [1] => Array
        (
            [28] => Array
                (
                    [Single] => 
                )

            [29] => Array
                (
                    [Single] => 
                )

            [24] => Array
                (
                    [28] => 
                )

            [22] => Array
                (
                    [28] => 
                )

            [11] => Array
                (
                    [7] => 
                )

            [23] => Array
                (
                    [7] => 
                )

        )

    [2] => Array
        (
        )




I have an idea on whats wrong but i am not sure what is the best way to fix it.

Im trying to have it nested as follows
array(
      [city_id] => array(
            [item_id] => array(
                  [unit] => array(
                        [0] => array(
                              [price] => 0,
                              [qty] => 0
                        ),
                        [1] => ...
                  )
            )
      )
);


But when you check out the output and the jsons being displayed you can see item 28 is not being added 2x given there is 2 entries for that item id.

This post has been edited by Bobby_Bubbles: 08 November 2019 - 01:23 PM

Was This Post Helpful? 0
  • +
  • -

#9 ArtificialSoldier   User is offline

  • D.I.C Lover
  • member icon

Reputation: 2494
  • View blog
  • Posts: 7,551
  • Joined: 15-January 14

Re: parsing JSON but cant pull info

Posted 08 November 2019 - 01:37 PM

The first thing to do is deal with all of those warnings, if the array doesn't exist yet then make a new array before trying to push something to it. Use isset to check if it exists first.
Was This Post Helpful? 0
  • +
  • -

#10 Bobby_Bubbles   User is offline

  • D.I.C Regular

Reputation: 1
  • View blog
  • Posts: 339
  • Joined: 13-March 18

Re: parsing JSON but cant pull info

Posted 08 November 2019 - 06:30 PM

it hangs on trying to insert a new item id with its array. if isset detects that there is no array then how would i deal with that?
Was This Post Helpful? 0
  • +
  • -

#11 ArtificialSoldier   User is offline

  • D.I.C Lover
  • member icon

Reputation: 2494
  • View blog
  • Posts: 7,551
  • Joined: 15-January 14

Re: parsing JSON but cant pull info

Posted 11 November 2019 - 10:08 AM

Just make a new array before trying to push. In your case you'll need to check several things. You need to make sure $saleinv[$value['merchant_id']] exists, and $saleinv[$value['merchant_id']][$value['item_id']] exists, and $saleinv[$value['merchant_id']][$value['item_id']]['Single'] exists before pushing. If any of those don't exist then just set it as an empty array.
Was This Post Helpful? 0
  • +
  • -

#12 Bobby_Bubbles   User is offline

  • D.I.C Regular

Reputation: 1
  • View blog
  • Posts: 339
  • Joined: 13-March 18

Re: parsing JSON but cant pull info

Posted 11 November 2019 - 11:18 AM

done the monster.

$saleinv = array(1 => array(),2 => array());
				$listitem = mysqli_query($conn,"SELECT merchant_id, item_id FROM mt_item ORDER BY item_id ASC");
				while($list = mysqli_fetch_array($listitem)){
					$saleinv[$list['merchant_id']] += array($list['item_id'] => array('Single' => array(),'7' => array(),'14' => array(),'28' => array(),'Total' => array(),'Pack of 7' => array()));
				}
				$query = mysqli_query($conn,"SELECT order_id, json_details FROM mt_order WHERE status='Delivered'")or die(mysqli_error($conn));
				while($fet = mysqli_fetch_array($query)){
					$result = json_decode($fet['json_details'],true);
					foreach($result AS $key=>$value){
						list($mprice,$w,$unk) = explode('|', $value['price']);
						$w = str_replace("g","",$w);
						if($w == '1' || $w == 'Sinle'){
							array_push($saleinv[$value['merchant_id']][$value['item_id']]['Single'],$mprice.'|'.$value['qty']);
						}elseif($w == '7'){
							array_push($saleinv[$value['merchant_id']][$value['item_id']][$w],$mprice.'|'.$value['qty']);
						}elseif($w == 'Pack of 7'){
							array_push($saleinv[$value['merchant_id']][$value['item_id']][$w],$mprice.'|'.$value['qty']);
						}elseif($w == '14'){
							array_push($saleinv[$value['merchant_id']][$value['item_id']][$w],$mprice.'|'.$value['qty']);
						}elseif($w == '28'){
							array_push($saleinv[$value['merchant_id']][$value['item_id']][$w],$mprice.'|'.$value['qty']);
						}else{
							echo 'NOT ACCOUNTED FOR : '.$w.'<br/>';
						}
					}
				}
				$loc = array(1 => 'Windsor',2 => 'Vaughn');
				foreach($loc AS $key=>$value){
					echo '<h2>'.$value.'</h2>';
					$itemq = mysqli_query($conn,"SELECT a.item_name, a.item_id, a.photo, b.base FROM mt_item AS a, base_price AS b WHERE a.merchant_id='$key' AND a.item_id=b.item_id ORDER BY a.item_id ASC")or die(mysqli_error($conn));
					echo '<table id="customers"><tr id="nonhead"><td align="right">Strain ID</td><td width="500">Strain Name</td><td width="150">Sold(# of units)</td><td align="right">Total</td><td width="200" align="right">Base Cost (per Oz)</td><td align="right"># of ounces</td><td align="right">Grant Total</td><td align="right">Profit</td></tr>';
					$sold = 0;
					$tprofit = $tgtotal = $ttotal = 0;
					while($res = mysqli_fetch_array($itemq)){
						$totals = $grams = $gtotal = $profit = '';
						echo '<tr><td valign="top">'.$res['item_id'].'</td><td valign="top"><img src="upload/'.$res['photo'].'" width="50" height="50"/>'.$res['item_name'].'</td>';
						echo '<td valign="top">';
						$p = $q = array('Single' => 0,'7' => 0,'14' => 0,'28' => 0,'Pack of 7' => 0);
						foreach($saleinv[$key][$res['item_id']] as $key3 => $value3){
							if(count($saleinv[$key][$res['item_id']][$key3]) > 0){
								echo $key3.' : ';
								foreach($saleinv[$key][$res['item_id']][$key3] as $key4 => $value4){
									list($price,$qty) = explode('|', $value4);
									$p[$key3] += $price;
									$q[$key3] += $qty;
								}
								echo $q[$key3];
								echo '</br>';
							}
						}
						foreach($q as $qkey => $qvalue){
							if($qvalue > 0){
								$totals .= number_format($p[$qkey],2).'<br/>';
								$ttotal += $p[$qkey];
								if($qkey == 'Pack of 7'){
									$grams  .= number_format($q[$qkey] * 7 / 28,2).' oz<br/>';
									$gtotal .= number_format($res['base'] * $q[$qkey] * 7,2).'<br/>';
									$tgtotal += $res['base'] * $q[$qkey] * 7;
									$profit .= number_format($p[$qkey] - $res['base'] * $q[$qkey] * 7,2).'<br/>';
								}elseif($qkey == 'Single'){
									$grams  .= number_format($q[$qkey] * 1 / 28,2).' oz<br/>';
									$gtotal .= number_format($res['base'] * $q[$qkey],2).'<br/>';
									$tgtotal += $res['base'] * $q[$qkey];
									$profit .= number_format($p[$qkey] - $res['base'] * $q[$qkey],2).'<br/>';
								}else{
									$grams  .= number_format($q[$qkey] * $qkey / 28,2).' oz<br/>';
									$gtotal .= number_format($res['base']*($q[$qkey]*$qkey/28),2).'<br/>';
									$tgtotal += $res['base']*($q[$qkey]*$qkey/28);
									$profit .= number_format($p[$qkey] - $res['base'] * $q[$qkey] * $qkey / 28,2).'<br/>';
								}
							}
						}
						if($res['base'] > 0){
							$msg = ' bgcolor="green"';
						}else{
							$msg = ' bgcolor="red"';
						}

						echo '</td><td valign="top" align="right">'.$totals.'</td><td valign="top"'.$msg.'><form action="?page=sales&do=save&sid='.$res['item_id'].'" method="post"><input type=text name=cost value="'.$res['base'].'" size="8" maxlength="8"/><input type=submit value="update"/></form></td><td valign="top" align="right">'.$grams.'</td><td valign="top" align="right">'.$gtotal.'<br/></td><td valign="top" align="right">'.$profit.'<br/></td></tr>';
					}
					echo '<tr><td>Grand Total</td><td colspan="2"></td><td align="right">Total</td><td colspan="2"></td><td align="right">Grand Total</td><td align="right">Profit</td></tr>';
					echo '<tr><td colspan="3"></td><td align="right">'.number_format($ttotal,2).'</td><td colspan="2"></td><td align="right">'.number_format($tgtotal,2).'</td><td align="right">'.number_format($ttotal-$tgtotal,2).'</td></tr>';
					echo '</table>';
				}



only thing left is to prepare the sql statements.

This post has been edited by Bobby_Bubbles: 11 November 2019 - 11:21 AM

Was This Post Helpful? 0
  • +
  • -

#13 JackOfAllTrades   User is offline

  • Saucy!
  • member icon

Reputation: 6259
  • View blog
  • Posts: 24,028
  • Joined: 23-August 08

Re: parsing JSON but cant pull info

Posted 11 November 2019 - 06:13 PM

if($w == '1' || $w == 'Sinle')


You sure you want 'Sinle' there?
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1