phpmysqlormredbean

Redbeanphp bad order


With this code, I parse post elements from table

$all = R::findAll('postdate'," ORDER BY id DESC LIMIT 15");
    for($i = 1; $i <= count($all); $i++){
        if(isset($all[$i])){
            $date = date_create($all[$i]->date);
            $post = R::findOne('post', 'date_id = ?', array($all[$i]->id));
            $author = R::findOne('postauthor', 'id = ?', array($post->author_id));
            $title = R::findOne('posttitle', 'id = ?', array($post->title_id));
            echo '<div class=post>
                      <i class=post-date>'.date_format($date, 'd.m.Y G:i').' 📝 '.$author->author.'</i>
                      <h1>'.$title->title.'</h1><hr><br>'.
                      $post->content.
                  '</div>';
        }
        
    }

but in the end the last posts are not found and everything goes in ascending order. Help me please. I tried it through the date too


Solution

  •         $all = R::getAll( 'SELECT * FROM postdate ORDER BY date DESC LIMIT 125' );
            for($i = -1; $i <= count($all); $i++){
                if(isset($all[$i])){
                    $date = date_create($all[$i]['date']);
                    $post = R::findOne('post', 'date_id = ?', array($all[$i]['id']));
                    $author = R::findOne('postauthor', 'id = ?', array($post->author_id));
                    $title = R::findOne('posttitle', 'id = ?', array($post->title_id));
                    echo '<div class=post>
                              <i class=post-date>'.date_format($date, 'd.m.Y G:i').' 📝 '.$author->author.'</i>
                              <h1>'.$title->title.'</h1><hr><br>'.
                              $post->content.
                          '</div>';
                }
            }