douhuangjian9627 2016-08-31 15:54
浏览 30
已采纳

推进多次返回相同的记录

I have a very simple database (MySql) with one table which I am accessing using Propel with this code...

<?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();
?>

The query seems to be generated correctly...

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

If I run this query through phpMyAdmin I get the expected results, however, Propel seems to be returning the first record found by the query 20 times. Anyone know what might be happening here? Thanks

edit: Record loop

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;
}
  • 写回答

1条回答 默认 最新

  • dsxcv5652 2016-08-31 17:55
    关注

    The schema I had generated from my existing database using propel's init command was created prior to setting a primary key for that table. This caused Propel to return the same record multiple times in one query. This was resolved by regenerating the schema with the primary key in place.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 目详情-五一模拟赛详情页
  • ¥15 有了解d3和topogram.js库的吗?有偿请教
  • ¥100 任意维数的K均值聚类
  • ¥15 stamps做sbas-insar,时序沉降图怎么画
  • ¥15 买了个传感器,根据商家发的代码和步骤使用但是代码报错了不会改,有没有人可以看看
  • ¥15 关于#Java#的问题,如何解决?
  • ¥15 加热介质是液体,换热器壳侧导热系数和总的导热系数怎么算
  • ¥100 嵌入式系统基于PIC16F882和热敏电阻的数字温度计
  • ¥15 cmd cl 0x000007b
  • ¥20 BAPI_PR_CHANGE how to add account assignment information for service line