gpt4 book ai didi

php - 插入多次返回相同的记录

转载 作者:行者123 更新时间:2023-11-29 01:51:55 26 4
gpt4 key购买 nike

我有一个非常简单的数据库 (MySql),其中有一个表,我正在使用带有此代码的 Propel 访问它...

<?php
$autoloader = require '/vendor/autoload.php';
$autoloader->add('', __DIR__ . '/generated-classes/');

use Propel\Runtime\Propel;
use Propel\Runtime\Connection\ConnectionManagerSingle;

require './generated-conf/config.php';
require './includes/pagebuilder.php';

Propel::getConnection("default")->useDebug(true);

$videos = VideosQuery::create()
->orderByAddeddate()
->paginate($page = 1, $maxPerPage = 20);

echo GetMainPage($videos);
echo Propel::getConnection()->getLastExecutedQuery();
?>

查询似乎生成正确...

SELECT videos.id, videos.AddedDate, videos.Rating, videos.Views, videos.Title, videos.Description, videos.ImageUrl, videos.EmbedUrl FROM videos ORDER BY videos.AddedDate ASC LIMIT 20

如果我通过 phpMyAdmin 运行此查询,我会得到预期的结果,但是,Propel 似乎返回查询找到的第一条记录 20 次。有人知道这里会发生什么吗?谢谢

编辑:记录循环

function GetMainContent($videos) {
$mc = '<main>
<div id="video-box-wrapper">';

foreach($videos as $video) {
$mc .= '<div class="video-box">
<a href="#">
<img src="' . $video->getImageUrl() . '" />
<span>' . $video->getTitle() . '</span>
<br />
<p>' . $video->getViews() . ' views</p>
<p>Rating: ' . $video->getRating() . '/10</p>
</a>
</div>';
}
$mc .= '</main>';

return $mc;
}

最佳答案

我使用 propel 的 init 命令从现有数据库生成的模式是在为该表设置主键之前创建的。这导致 Propel 在一次查询中多次返回相同的记录。这已通过使用适当的主键重新生成架构来解决。

关于php - 插入多次返回相同的记录,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39254080/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com