尝试验证我的代码时,我遇到了三个错误.
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标签,但我不认为它们会在这种情况下有效.

ID必须是唯一的.您在循环中使用相同的ID.你可以这样做:
$count = 1;
while ($recipe = mysql_fetch_assoc($recipes)) {
echo '<section id="recipeslide' . $count++ . '">';
Run Code Online (Sandbox Code Playgroud)
至于alt属性<img>,它几乎是必需的,即使它是空的.
| 归档时间: |
|
| 查看次数: |
47 次 |
| 最近记录: |