i’m trying to display unordered lists made with sql table columns but i get empty lists which i don’t get because when i type
echo $stories[0]['title'];
i get the value expected (jason).
I have tried with and without echo but the result is the same..
here is my table :
mysql> select * from story;
+----+-------+-------------------------+---------+
| id | title | content | author |
+----+-------+-------------------------+---------+
| 1 | jason | histoire des argonautes | guigous |
| 2 | jason | histoire des argonautes | guigous |
and my html :
<?php
require 'connec.php';
$pdo = new PDO(DSN,USER,PASS);
$query ='select * from story';
$statement = $pdo->query($query);
$stories= $statement->fetchAll();
?>
<!DOCTYPE html>
<body>
<?php
echo $stories[0]['title'];
for ($i=0; count($stories)>$i; $i++) :
?>
<ul>
<li> <? echo $stories[$i]['title']?></li>
<li><? echo $stories[$i]['content']?></li>
<li><? echo $stories[$i]['author']?></li>
</ul>
<?php endfor; ?>
</body>
thanks you for your time !
>Solution :
Can you try this code, not sure is correct or not, also it will be great if you can provide exported SQL table so we can replicate the environment
But meanwhile you can try this code:
<?php
for(int $i = 0; $i < count($stories); $i++) {
?>
<ul>
<li><?php echo $stories[$i]['id']; ?></li>
<li><?php echo $stories[$i]['title']; ?></li>
<li><?php echo $stories[$i]['content']; ?></li>
<li><?php echo $stories[$i]['author']; ?></li>
</ul>
<?php
}
?>