如何制作如下结果

时间:2011-06-29 05:52:05

标签: php mysql

我想创建一个db结果,如下所示:

<div class="entries">
  <div class="page"> <a href="KimAronson-TwentySeconds59483.m4v" class="first"> Palm trees and a hot sun <br />
    <em>0:20 min</em> </a> <a href="KimAronson-TwentySeconds58192.m4v"> Playing around with toes <br />
    <em>0:20 min</em> </a> <a href="KimAronson-TwentySeconds63617.m4v"> Small lake and a bicycle <br />
    <em>0:20 min</em> </a> <a href="KimAronson-TwentySeconds64268.m4v"> Hotel Room 213 In San Fransisco <br />
    <em>0:20 min</em> </a> </div>
  <div class="page"> <a href="KimAronson-TwentySeconds67463.m4v"> Some Hebrew letters on a paper<br />
    <em>0:20 min</em> </a> <a href="KimAronson-TwentySeconds65459.m4v"> Driving Golden gate bridge <br />
    <em>0:21 min</em> </a> <a href="KimAronson-TwentySeconds70930.m4v"> Eating Sushi and being trendy <br />
    <em>0:21 min</em> </a> <a href="KimAronson-TwentySeconds72119.m4v"> Big spider web on home garden <br />
    <em>0:23 min</em> </a> </div>
  <div class="page"> <a href="KimAronson-TwentySeconds71844.m4v"> Random Miniature Characters <br />
    <em>0:21 min</em> </a> <a href="KimAronson-TwentySeconds73213.m4v"> Things on the table and hidden camera <br />
    <em>0:21 min</em> </a> <a href="KimAronson-TwentySeconds75235.m4v"> Two little girls hand in hand <br />
    <em>0:21 min</em> </a> <a href="KimAronson-TwentySeconds67463.m4v"> Hebrew writings on paper again<br />
    <em>0:20 min</em> </a> </div>
</div>

任何人都可以告诉我如何使用以下查询

$sql = "SELECT id, video_name, video_file_name, thumbnail_image, is_default FROM videos ORDER BY is_default DESC";
            $result = mysql_query($sql);
            $num = mysql_num_rows($result);
            $per_div = ceil($num/4);
            //echo "Per Div " . $per_div;
            while($row = mysql_fetch_array($result)){
                echo '<div class="page">';
                    while($row1 = mysql_fetch_array($result)){
                        echo '<a href="KimAronson-TwentySeconds59483.m4v"> Palm trees and a hot sun <br />
    <em>0:20 min</em> </a>';    
                    }
                echo '</div>';  
            }

由于

2 个答案:

答案 0 :(得分:2)

编辑:假设您希望将结果分为四组:

$sql = "SELECT id, video_name, video_file_name, thumbnail_image, is_default FROM videos ORDER BY is_default DESC";
$result = mysql_query($sql);
$out = array('<div class="page">');
$i = 0;
while($row = mysql_fetch_array($result)){
    $out[] = '<a href="' . htmlspecialchars($row['video_file_name']) . '"> ' . htmlspecialchars($row['video_name']) . ' <br /><em>?:?? min</em> </a>';
    if ($i % 4 === 0) {
        $out[] = '</div>';
        $out[] = '<div class="page">';
    }
    $i++;
}
$out[] = '</div>';
print implode("\n", $out);

(未测试的)

答案 1 :(得分:1)

您可能需要尝试此操作

foreach ($result as $row) {
echo "<a href=".$row['video_file_path']."> ". $row['video_name']."</a>"
}