第70行,第191列:重复ID配方滑动.有解决方法吗?

Law*_*ith -1 html php

尝试验证我的代码时,我遇到了三个错误.

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>';
Run Code Online (Sandbox Code Playgroud)

这是我使用recipeslide的唯一的地方,但我认为验证器在某种程度上变得困惑,并想知道如何解决这个问题或者我是否忽略它?

它指出了另外两个被认为是重复的Id.

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

在此输入图像描述

Exp*_*lls 5

ID必须是唯一的.您在循环中使用相同的ID.你可以这样做:

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

至于alt属性<img>,它几乎是必需的,即使它是空的.