0

I'm learning PHP and somehow when I try to fetch data from database this is the query:

select ItemId, ItemName, ItemPrice, ItemPicture
from Webshop_Items
where ItemId = 12

This is the SSMS data:

ItemId  ItemName    ItemPrice   ItemPicture
12      Cool Item   11          DFEAEC2D-9AE8-4329-8942-C20381C7795F.png

This is the array that I'm receiving back and I cannot use it like this

$result = ....
echo '<a>$result['ItemName'];</a>'

When I added logs to print the data its look like this:

a:1:{i:0;a:4:{s:6:"ItemId";i:7;s:12:"ItemName";s:9:"Cool Item";s:9:"ItemPrice";i:10;s:11:"ItemPicture";s:40:"DFEAEC2D-9AE8-4329-8942-C20381C7795F.png";}}

Thanks in advance.

Dale K
  • 25,246
  • 15
  • 42
  • 71
  • 2
    you left an important part out of your code with just `$result = ....` – empiric Sep 10 '21 at 11:20
  • 1
    From the logs, `$result` is an array of arrays. It contains all matching rows (in your case: one row). So you'll want to get `ItemName` from the first row, like `$result[0]['ItemName']`. – rickdenhaan Sep 10 '21 at 11:20
  • Does this answer your question? [How to use php serialize() and unserialize()](https://stackoverflow.com/questions/8641889/how-to-use-php-serialize-and-unserialize) – CBroe Sep 10 '21 at 11:26

0 Answers0