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条)

报告相同问题?