-1

尝试验证我的代码时出现三个多重错误。

echo '<section id="featured">';
    $recipes = mysql_query("
        SELECT `id`,`name`, `image`, `description`
        FROM `recipe` 
        ORDER BY RAND() LIMIT 4;
    ");

    while ($recipe = mysql_fetch_assoc($recipes)) {
    echo '<section id="recipeslide">';
    $recipe_id = $recipe['id'];


    echo "<a href='php/recipe.php?id=$recipe_id'><img src=\"{$recipe['image']}\" height=100 width=100 /></a><br />";

    echo '</section>';
    }


    echo '</section>';

这是我唯一使用 recipeslide id 的地方,但我认为验证器不知何故感到困惑,想知道如何解决这个问题,还是忽略它?

它指出了另外两个据称重复的 ID。

它也在抱怨 alt 标签,但我认为它们在这种情况下不会有效。

在此处输入图像描述

4

2 回答 2

5

IDs must be unique. You are using the same ID in a loop. You could do something like:

$count = 1;
while ($recipe = mysql_fetch_assoc($recipes)) {
    echo '<section id="recipeslide' . $count++ . '">';

As for the alt attribute for <img>, it's pretty much required even if it's empty.

于 2013-05-16T16:25:12.983 回答
0

You are giving an id in a loop

So you get an extra ID each time round the loop

if you have 3 recipes then the while loop runs 3 times with each insertion adding another

<section id="recipeslide">

The answer is to not set a static id on an element inside of a loop, you need to either use a unique id for each run through the loop or if it is just for styling, set a class rather than an id

于 2013-05-16T16:23:47.807 回答