运行此命令后,我不断得到一个奇怪的列表:
<?php
$query_Category = "SELECT * FROM blog_categories ORDER BY category ASC";
$getCategory = mysql_query($query_Category) or die(mysql_error());
?>
<div id="sheader" style="">Categories</div>
<div class="sbody" style="color:#000 !important;">
<?php
do {
?>
<div><?php echo $row_getCategory['category'];?></div>
<?php
$cat = $row_getCategory['cat_id'];
$query_Subcategory = "SELECT * FROM blog_subcategories WHERE primcat_id = '$cat' ORDER BY subcategory ASC";
$getSubCategory = mysql_query($query_Subcategory) or die(mysql_error());
$row_getSubCategory = mysql_fetch_assoc($getSubCategory);
$str = $row_getSubCategory['subcategory']; $subcategory = explode(',', $str);
foreach ($subcategory as $arraysubcat)
{
echo '<div>' . $arraysubcat . '</div>';
}
} while ($row_getCategory = mysql_fetch_assoc($getCategory));
?>
</div>
<?php mysql_free_result($getCategory); ?>
我有一个带有 id 和类别的类别表和一个带有 id、子类别和主要类别 id 的子类别表。我运行它,它首先随机显示 foreach。