I guess I have a really simple question. I have a simple HTML page which I want to fill up with words from a mysql database.
Therefore I wrote this little test page. My problem is, that the first echo "Picture" works fine but the second one "Name" won't output anything. It works only the first time. If I add this:
$sql = <<<SQL
SELECT *
FROM `Database1`
WHERE `id` = 1
SQL;
if(!$result = $db->query($sql)){
die('There was an error running the query [' . $db->error . ']');
}
while($row = $result->fetch_assoc()){
before the second echo "Name" everything works fine.
<?php
$db = new mysqli('', '', '', '');
if($db->connect_errno > 0){
die('Unable to connect to database [' . $db->connect_error . ']');
}
$sql = <<<SQL
SELECT *
FROM `Database1`
WHERE `id` = 1
SQL;
if(!$result = $db->query($sql)){
die('There was an error running the query [' . $db->error . ']');
}
?>
<html>
<img src="<?php
while($row = $result->fetch_assoc()){
echo $row['Picture'];}
?>" height="270">
some more html...
<?php
echo $row['Name'] . '<br />';
?>
even more html...
<?php
mysqli_close ($con);
?>
</html>
Is this the way to go? Or did I miss something?
Thank you!
echo $row['Picture'];}you have ended thewhileloop of php. So whatever comes after it, will not show.