0
我是PHP新手,正在創建博客。 我正在實現一個滑塊,我只是想知道如何有一個類似Rails的方法.each
。Rails到PHP每個sql查詢
在Rails,以下是可能的
<div class="main-slider section">
<% @posts.each do |post| %>
<div class="item">
<a href="<%= post.the_permalink %>" >
<%= post.the_post_thumbnail %>
</a>
<div class="post-info">
<div class="title">
<h2><a href="<%= post.the_permalink %>"><%= post.title %></a></h2>
<div class="sep"></div>
</div>
<div class="post-excerpt">
<% if post.excerpt.length > 150 %>
<%= truncate(post.excerpt, length: 150) %>
<%= link_to_function 'Read more', "$(this).parent().html('#{escape_javascript post.excerpt}')" %>
<% else %>
<%= post.excerpt %>
<% end %>
</div>
<div class="read-more">
<a href="<%= post.the_permalink %>">Read more</a>
</div>
</div>
</div>
</div>
我如何將Ruby代碼轉換這PHP,其中<div class="item"> [...] </div>
是基於數據庫的帖子數量環。 謝謝
使用[的foreach(http://us2.php.net/manual/en/control-structures。 foreach.php) – Leonardo