1

I have a question about my code. When i try to fill my html with my fetched array i only get blank spaces instead of the actual results. Can anyone tell me why ?

<?php
require_once("php/loader.inc.php");
include("php/header.php");
include("php/userpanel.php");
$gebruiker = $_SESSION['user'];
?>


<div class="large-8 columns">
<div class="row">  


<?php
$query = "
SELECT
   items.naam,
   items.prijs,
   items.image_url
FROM inventory
JOIN items
 ON items.id = inventory.item_id
WHERE
 gebruiker_id = ?
";

$stmt = $db->prepare($query);
$stmt-> bind_param('i', $gebruiker->id);

$stmt->execute();

$result = $stmt->get_result();
while ($row = $result->fetch_assoc())
{
    $user_items[] = $row;

   echo '<div class="large-3 small-4 columns">
<img src="'. $user_items['image_url'] .'">
<div class="panel">
    <h6>'. $user_items['naam'] .'</h6>
<h6 class="subheader">'. $user_items['prijs'] .'</h6>
</div>
</div>'; 

}
?>

By the way, when i try print_r($user_items); it gives me the expected result.

Thanks in advance!

2 Answers 2

2

I think you want to change this:

$user_items[] = $row;

to this:

$user_items = $row;

Otherwise your indexes are 1 dimension 'deeper'

As an example:

$row = array("image_url" => "xy");

after this line:

$user_items[] = $row;

You can't access it with:

echo $user_items["image_url"];  //Wrong

you would have to do this:

echo $user_items[0]["image_url"];  //works
Sign up to request clarification or add additional context in comments.

Comments

1

You don't need this line $user_items[] = $row; you can use $row directly

while ($row = $result->fetch_assoc())
{        
   echo '<div class="large-3 small-4 columns">
  <img src="'. $row['image_url'] .'">
  <div class="panel">
    <h6>'. $row['naam'] .'</h6>
    <h6 class="subheader">'. $row['prijs'] .'</h6>
  </div>
  </div>';     
}

1 Comment

Haha yes i will as soon as the timer restriction is off the button :)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.