【发布时间】:2016-10-21 13:48:18
【问题描述】:
我在 phpmyadmin 上有一个数据库,我想将一些数据(不是所有数据)从一个表显示到 HTML/PHP 上的一个表中。我无法弄清楚我的代码有什么问题。每个表格行必须有 3 个单元格。这就是我在 php 脚本中使用 $nrArt 变量的原因。你能帮忙吗?
<table class="art-content">
<div class="row">
<? php
try {$cnx= new PDO("mysql:host=localhost;charset=utf8;dbname=restaurant","root", "");
$interogare=$cnx -> prepare("SELECT id_preparat, nume, pret, foto from preparate WHERE id_categorie= 1");
$interogare -> execute();
$nrArt = 0;
foreach ($interogare-> fetchAll() as $linie){
$id=$linie["id_preparat"];
$nume=$linie["nume"];
$pret=$linie["pret"];
$img=$linie["foto"];
if($nrArt==0){
echo '<tr class="col-1-3">';
}
echo '<div class="wrap-col">';
echo '<td class="item-container">';
echo'<a class="example-image-link" href="images/'.$img.'" data-lightbox="example-set" data-title="'.$nume.'">';
echo '<div class="item-caption">';
echo '<div class="item-caption-inner">';
echo'<div class="item-caption-inner1">';
echo'<h3>Pret</h3>';
echo '<span>'.$pret.'RON</span>';
echo'</div>';
echo '</div>';
echo '</div>';
echo '<img class="example-image" src="images/'.$img.'" alt=""/>';
echo'</a>';
echo '</td>';
$nrArt++;
if($nrArt>2){
echo '</tr>';
}
}
}
catch (PDOException $e){
die("Conectare imposibila: ". $e -> getMessage()); }
?>
</div>
</table>
【问题讨论】:
标签: php html phpmyadmin xampp