我想设计广告横幅,以php和HTML格式显示来自数据库的广告图像。
我使用了下面的代码,但是没有一一显示所有图像。
<?php
$sql = "select * from tbl_ads where id='8'";
$q = mysql_query($sql);
while ($row = mysql_fetch_assoc($q)) {
?>
<div class="col-lg-12 col-md-12 col-sm-12 col-xs-12 add-banner">
<a target="_blank" href="<?php echo $row['link']; ?>">
<img src="adminpanel/files/<?php echo $row['upload']; ?>" alt="footer" style="margin-top: 15px;margin-left: 10px; height: 150px; width: 1500px; margin-left: 100px;">
</a>
</div>
<?php
}
?>
您的错误来自您从数据库代码获取记录。此扩展名MYSQL
在PHP 5.5.0中已弃用,在PHP 7.0.0中已被删除。而是使用MySQLi
或PDO_MySQL
扩展名,像这样
<?php
//Connection like this..(localhost,username,password,dbname)
$con=mysqli_connect("localhost","my_user","my_password","my_db");
// Check connection
if (mysqli_connect_errno())
{
echo "Failed to connect to MySQL: " . mysqli_connect_error();
}
$sql="SELECT Lastname,Age FROM Persons ORDER BY Lastname";
if ($result=mysqli_query($con,$sql))
{
// Fetch one and one row
while ($row=mysqli_fetch_row($result))
{
//returns same results as your previous try. but the syntax is little way different.
echo $row[1];
}
}
mysqli_close($con);
?>