使用HTML创建广告横幅标签

问题描述 投票:-3回答:1

我想设计广告横幅,以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 

} 

?>
php ads banner
1个回答
0
投票

您的错误来自您从数据库代码获取记录。此扩展名MYSQL在PHP 5.5.0中已弃用,在PHP 7.0.0中已被删除。而是使用MySQLiPDO_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);
?>
© www.soinside.com 2019 - 2024. All rights reserved.