Hey all I have a table caleld Box1, with a simple structure of: id(increment,primary) imageurl, 开发者_Go百科link.
What I am looking to do, is on my site in the HTML file, display the imageurl into a imgsrc, so that the Image URL loads the image when going to the site
I cannot find specifically what I am looking for online and know I must be close somewhere, this is what I have so far in my coding for my .php file.... thanks.
<?php
$con = mysql_connect("localhost","data","data");
if (!$con)
{
die('Could not connect: ' . mysql_error());
}else {
mysql_select_db("database1", $con);
$result = mysql_query("SELECT * FROM Box1 ORDER BY id DESC LIMIT 1");
while($row = mysql_fetch_array($result))
{
echo $row['image'];
// NEXT STEP IS TO DISPLAY THE the IMAGE EXAMPLE: '<img src code<?php echo 'image'; ?>' >
}
}
mysql_close($con)
?>
if you could guide me to an exmaple of how to do this, that would be amazing, im so confused how one would implement HTML with PHP, thanks!!
<?php
... connect to DB ...
$sql = "SELECT imgurl FROM Box1 WHERE id=XXX";
$result = mysql_query($sql) or die(mysql_error());
$row = mysql_fetch_assoc($result);
?>
<img src="<?php echo $row['imgurl'] ?>" />
Also, it is helpful to become familiar with this operator for large chunks of html
echo <<<YOUR_TOKEN_NAME
<img src="$row['imgurl']" />
...misc html and php vars intermixed
YOUR_TOKEN_NAME;
精彩评论