Fake
Fake

Reputation: 159

Get an Array in results from SQL in PHP

i'm doing

$sql = $_SESSION['data']->bySQL("SELECT * FROM worlds WHERE field='shippingLicenseItemName'");

and then printing result(i know it is very simple but i'm learning by myself through this site)

echo nl2br(print_r($sql, true));

and in result i'm getting array like this :

 Array
(
[atlantis] => Array
(
[shippingLicenseItemName] => pkg_atlantisXfer
)

[australia] => Array
(
[shippingLicenseItemName] => pkg_australiaXfer
)

[avalon] => Array
(
[shippingLicenseItemName] => pkg_avalonXfer
)
)

but i want the results like : World : "atlantis" and item : "shippingLicenseItemName" and code is : "pkg_atlantisxfer"

World : "australia" and item : "shippingLicenseItemName" and code is : "pkg_australiaxfer"

Upvotes: 2

Views: 42

Answers (1)

Nick Andriopoulos
Nick Andriopoulos

Reputation: 10653

Don't know where you found the bySQL property, it seems to be returning the data keyed by a column on its own, making things a tad more complicated.

But i'ts nothing you cannot solve with a couple of loops :

foreach($sql as $o_key=>$o_data) {
   foreach($o_data as $i_key=>$i_data) {
     print "World $o_key and item : $i_key and code is $i_data <br />"l
   }
}

Upvotes: 1

Related Questions