0

我正在创建位于此处的网站

我正在尝试添加每次页面刷新时都会更改的横幅。我在我的数据库中设置了 2 个示例,称为“链接 1”和“链接 2”。当我得到它们时,我会想添加更多。

我想要发生的是:

我想在我的网站上显示 2 张图片中的一张,当用户刷新页面时,它将选择 2 张图片中的一张,并且每次页面刷新时都会继续。

在将它移到我的footer.php 并使其生效之前,我在一个名为banner.php 的页面中对此进行了测试。

我目前在我的banner.php页面中有这段代码:

<?PHP
include_once('include/connection.php');

// Edit this number to however many links you want displaying
$num_displayed = 1 ;

// Select random rows from the database
    global $pdo;
      $query = $pdo->prepare ("SELECT * FROM banners ORDER BY RAND() LIMIT $num_displayed"); 
      $query->execute();

// For all the rows that you selected
while ($row = execute($result)) 

{
// Display them to the screen...

echo "<a href=\"" . $row["link"] . "\">
<img src=\"" . $row["image"] . "\" border=0 alt=\"" . $row["text"] . "\">
</a>" ;
}
?>
<br /><br /><br />

但我收到此错误代码:

致命错误:在第 13 行的banner.php 中调用未定义函数execute()

我的连接页面被其他页面使用,所以我知道它有效。

请有人帮我解决我做错了什么。

需要更多信息,请询问,我会将其添加到这篇文章中。

谢谢你。

凯夫

4

1 回答 1

1

替换这个

while ($row = execute($result)) 

有了这个:

while ($row = $query->fetch())

编辑

这使它更好地阅读。

while ($row = $query->fetch()) :
// Display them to the screen...
?>
<a href="<?php echo $row['link']; ?>">
<img src="<?php echo $row['image']; ?>" border="0" alt="<?php echo $row['text'];?>">
</a>
<?php endwhile; ?>
<br/>
<br/>
<br/>
于 2013-09-23T13:59:12.990 回答