我想在三列中显示我的sql结果,如下面的格式。
怎么可能?我应该用tr和td添加表吗?还是我的代码中的div?
CategoryName1 CategoryName2 CategoryName3
subcategoryN subcategoryN subcategoryN
<?php
foreach ($resultLang as $oneRec)
{
$catid= $oneRec["categoryID"];
echo"<strong>".$oneRec["categoryName"]."</strong><br>";
$sqlCmd2 ="SELECT subcategories.subCatID,subcategories.subCatName
FROM subcategories
JOIN categories
ON subcategories.categoryID=categories.categoryID
JOIN languages
ON categories.languageID = languages.languageID
WHERE languages.languageID =:lang
AND categories.categoryID=:cboCat";
$prepQuery2 = $conn ->prepare($sqlCmd2);
$prepQuery2->bindParam(":lang",$langTemp, PDO::PARAM_INT);
$prepQuery2->bindParam(":cboCat",$catid, PDO::PARAM_INT);
$prepQuery2->execute();
$resultLang2= $prepQuery2->fetchAll();
foreach ($resultLang2 as $oneRec)
{
$subCatid=$oneRec["subCatID"];
echo "<a href='displaysubcategory.php?subcat=?$subCatid'>".$oneRec["subCatName"]."</a></br>";
}
echo "<br>";
}
答案 0 :(得分:2)
<?php
echo"<ul class='maincats'>";
foreach ($resultLang as $oneRec)
{
$catid= $oneRec["categoryID"];
echo"<li>";
echo"<strong>".$oneRec["categoryName"]."</strong>";
$sqlCmd2 ="SELECT subcategories.subCatID,subcategories.subCatName
FROM subcategories
JOIN categories
ON subcategories.categoryID=categories.categoryID
JOIN languages
ON categories.languageID = languages.languageID
WHERE languages.languageID =:lang
AND categories.categoryID=:cboCat";
$prepQuery2 = $conn ->prepare($sqlCmd2);
$prepQuery2->bindParam(":lang",$langTemp, PDO::PARAM_INT);
$prepQuery2->bindParam(":cboCat",$catid, PDO::PARAM_INT);
$prepQuery2->execute();
$resultLang2= $prepQuery2->fetchAll();
if($resultLang2) {
echo"<ul class='subcats'>";
foreach ($resultLang2 as $oneRec)
{
$subCatid=$oneRec["subCatID"];
echo"<li>";
echo "<a href='displaysubcategory.php?subcat=?$subCatid'>".$oneRec["subCatName"]."</a>";
echo"</li>";
}
echo"</ul>";
}
echo"</li>";
}
echo"</ul>";
之后根据你的设计主题使用float,display:inline-block属性为maincats和subats类创建一些CSS规则。
答案 1 :(得分:0)
我不知道eclipse标签是什么,但我通常做的是:
$header = "";
$data = "";
foreach ($resultLang2 as $oneRec)
{
$header .= "<td>".$oneRec['field']."</td>";
$data .= "<tr><td>".$oneRec['someData']."</td><td>".$oneRec['someOtherData']."</td></tr>";
}
echo "<table>";
echo "<tr>".$header."</tr>";
echo $data;
echo "</table>";