doucigua0449 2012-04-21 20:48
浏览 38
已采纳

使用符合要求的php显示数据库中的数据

I am designing an event feed from a calender I made. I'm using the same data from the database but to match specific dates and times.

  1. I only want 4 events to show at once (why I specified length < 4)
  2. Where the database value 'showFeed' is true, it only displays those rows.
  3. and I want it to show by date time, I have odd id's for each value in the database, which might make them out of order.

My current code:

$sql = "SELECT `title`, `time`, `start`, `showFeed` FROM calender WHERE length('column') > '0'";

$result = $dbh->query($sql)->fetchAll(PDO::FETCH_ASSOC);

echo "<div class=\"eventfeed\">";
echo "<ul>";

foreach ($result as $row){

$show = $row['showFeed'];

if ($show == 1 && length.$result < 4){
    echo "<li>";
    echo $row['title']. "<br />";
    echo $row['start'].' '.$row['time'];
    echo "</li>";
} 
else {

    return false;
}
}

echo "</ul>";
echo "</div>";

$dbh = null;

echo json_encode($return);

?>

I'm getting results and no errors from the database, but I'm only seeing one return on $results.

I honestly, do not have a clue where else to go from here. I'm lost.

  • 写回答

2条回答 默认 最新

  • dozpv84422 2012-04-21 20:59
    关注

    For 1+.2.+3. modify your query to SELECT title, time, start, showFeed FROM calender WHERE length('column') > '0' and showFeed=1 and time<current_timestamp ORDER BY time DESC LIMIT 0,3 and remove your if (...) statement.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥20 怎么用dlib库的算法识别小麦病虫害
  • ¥15 华为ensp模拟器中S5700交换机在配置过程中老是反复重启
  • ¥15 java写代码遇到问题,求帮助
  • ¥15 uniapp uview http 如何实现统一的请求异常信息提示?
  • ¥15 有了解d3和topogram.js库的吗?有偿请教
  • ¥100 任意维数的K均值聚类
  • ¥15 stamps做sbas-insar,时序沉降图怎么画
  • ¥15 买了个传感器,根据商家发的代码和步骤使用但是代码报错了不会改,有没有人可以看看
  • ¥15 关于#Java#的问题,如何解决?
  • ¥15 加热介质是液体,换热器壳侧导热系数和总的导热系数怎么算