-2

sorry to bother you guys, but been trying everything i could to get some data from database, and all the time it show's me blank, so i'm getting blank flashes as well :)

So what i need to to is,

database data

as you see on the pic, i have a column ownerId with repeated data, this is ok, i work's like that, now what i want extract from the database is to show the itemId and count where ownerId = ?.

So have my query as bellow.

<table id="zctb" class="display table table-striped table-bordered table-hover" cellspacing="0" width="100%">
<thead>
    <tr>
            <th>#</th>
            <th>Item Name</th>
            <th>Item ID</th>
            <th>Quantity</th>
    </tr>
</thead>

<tbody>

<?php   
$sql = "SELECT ownerId, itemId, count from user_item where ownerId = :editid";
$query = $dbh2 -> prepare($sql);
$query->bindParam(':editid',$editid,PDO::PARAM_INT);
$query->execute();
$result=$query->fetch(PDO::FETCH_ASSOC);
$cnt=1; 

if($query->rowCount() > 0){
    foreach($results as $result){               
?>  
            <tr>
                <td><?php echo htmlentities($cnt);?></td>
                <td><?php echo htmlentities($result->item_name);?></td>
                <td><?php echo htmlentities($result->itemId);?></td>
                <td><?php echo htmlentities($result->count);?></td>
            </tr>
<?php 
        $cnt=$cnt+1; 
    }
} 
?>

        </tbody>
    </table> 

but this don't return anything not even not data found on the table.

any idea?

RiggsFolly
  • 93,638
  • 21
  • 103
  • 149

1 Answers1

1

1) Check if you have a value in the variable $editid

2) you have an error in iterating over an array: foreach ($results as $result) // you don't have a $results variable

mazuro
  • 32
  • 6
  • Yes , with your answer i fix the issue. need to be like this prepare($sql); $query->bindParam(':editid',$editid,PDO::PARAM_INT); $query->execute(); $results=$query->fetchAll(PDO::FETCH_OBJ); $cnt=1; if($query->rowCount() > 0) { foreach($results as $result) { ?> – Tiago Ferreira Jun 19 '20 at 20:11