简体   繁体   English

foreach循环在while循环中使用list元素内的div

[英]foreach loop in while loop with div inside list element

hello guys i am trying to make a foreach loop in a while loop. 您好,我正在尝试在while循环中创建一个foreach循环。 in foreach loop i try to produce list elements with divs inside them but i have very strange output 在foreach循环中,我尝试在其中生成带有div的列表元素,但我的输出非常奇怪

here is my code 这是我的代码

$countercat= 0;
$classvar= 1;
echo "<div class='selector-page'>";
echo "<div class='selector'>";
echo "<ul>";
while ($countercat <= 8){
  $stmt=$conn->prepare('SELECT eidos, name,  meta_keys, address, telephone, perioxi, st_img, st_open, st_close, lat, longtit FROM magazia WHERE perioxi= :perioxi AND eidos= :eidos  ORDER BY st_id ASC');
$stmt->bindParam(':perioxi', $name, PDO::PARAM_STR);
$stmt->bindParam(':eidos', $eidos, PDO::PARAM_STR);
$eidos= $c_titles[$countercat]['c_name'];
$stmt->execute();
$allrows=$stmt->fetchAll(PDO::FETCH_ASSOC);
foreach($allrows as $row) {
  echo "<li>";
  echo "<div class='p". $classvar . " w3-card targetDiv w3-margin-top cardsmar'>";
  echo "<img src='../uploads/" . $row['st_img'] . "' class='cccard' alt='" . $row['name'] . "'";
  echo "<div class='w3-container w3-center'>";
  echo "<h3>" . $row['name'] ."</h3>";
  echo "<p>" . $row['eidos'] . "</p>";
  echo "<p>" . $row['address'] . " , " . $row['perioxi'] . "</p>";
  echo "<p>" . $lang['wrlt'] . " : " . $row['st_open'] . "-" . $row['st_close'] . "</p>";
  echo "<a href='katastimata.php?name=" . $row['name'] . "' role='button' class='w3-button w3-round w3black'>" . $lang['t9'] . "</a><br />";
  echo "<a href='https://www.google.com/maps?q=loc:" . $row['lat'] . "," . $row['longtit'] . "' role='button' class='w3-button w3-round w3-green btnmar'>" . $lang['spot2'] . "</a>";
  echo "</div>";
  echo "</div>";
  echo "</li>";

}
$countercat++;
$classvar++;

  }
  echo "</ul>";
  echo "</div>";
  echo "</div>";
}

?>

here is an image from my debugger consonle 这是我的调试器协奏曲的图像

在此处输入图片说明

as you see in the image inside in the ul tag exists only one li elemenemt and the rest of them are out side ul /ul. 如您在ul标记内的图像中看到的那样,只有一个li elemenemt,其余的在ul / ul之外。

my first thought was that is not valid to put div tag in a li tag but this is not true if i use this in the top of my file 我首先想到的是将div标签放在li标签中是无效的,但是如果我在文件顶部使用它,那是不正确的

DOCTYPE html PUBLIC "-//W3C// DTD XHTML 1.0 Transitional//EN"" http://www.w3.org/TR/xhtml1/DTD/html1-transitional.dtd " html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang:"en" DOCTYPE html PUBLIC“-// W3C // DTD XHTML 1.0 Transitional // EN”“ http://www.w3.org/TR/xhtml1/DTD/html1-transitional.dtd ” html xmlns =“ http:// www .w3.org / 1999 / xhtml“ xml:lang =” zh-CN“ lang:” zh-CN“

i am stack here for so long 我在这里堆了这么久

what am i missing guys? 我想念谁?

thanks in advance 提前致谢

vaggelis 瓦格里斯

You Didn't Close the <img> tag here. 您没有在此处关闭<img>标签。

echo "<img src='../uploads/" . $row['st_img'] . "' class='cccard' alt='" . $row['name'] . "'";

You Must Close the tag as 您必须关闭标签为

echo "<img src='../uploads/" . $row['st_img'] . "' class='cccard' alt='" . $row['name'] . "'/>";

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM