Php 使用>符号拆分关联数组并在列表中显示它
我开发了一个sql表,在该表中,我将与提要文件中的产品相关的详细信息放入其中。sql表中有一个字段,其名称为category1>category2>category3。我想用>符号拆分此列,并将其显示在列表中 现在我把它们放在一个关联数组中,但我不知道如何拆分数组的category元素并将其显示在列表中Php 使用>符号拆分关联数组并在列表中显示它,php,mysql,sql,arrays,Php,Mysql,Sql,Arrays,我开发了一个sql表,在该表中,我将与提要文件中的产品相关的详细信息放入其中。sql表中有一个字段,其名称为category1>category2>category3。我想用>符号拆分此列,并将其显示在列表中 现在我把它们放在一个关联数组中,但我不知道如何拆分数组的category元素并将其显示在列表中 <?php $firstsql='SELECT TOP 1 from xml where ('.implode('AND',$parts).')'; $firstsql3=mysql_qu
<?php
$firstsql='SELECT TOP 1 from xml where ('.implode('AND',$parts).')';
$firstsql3=mysql_query($firstsql);
$firstrow=array();
while($row = mysql_fetch_array($firstsql3)) {
// Append to the array
$firstrow[] = $row;
//echo $row['PID']."<BR />";
}
请指导我怎么做。如果我明白了,你可以做
$categories = explode(">",$row["category"]);
foreach ($categories as $category) {
// Do what you need with each $category, it will be "MEN", "CLOTHING" and "SHOES" each time
}
你真的应该考虑规范化你的数据库/为你的类别使用一个单独的表,并使用一个表将它们链接到产品。这意味着你说我应该创建两个列,一个带类别,一个带子类别,然后我应该以我需要的方式显示它们。是吗?TOP不是mysql函数/运算符!?!
$categories = explode(">",$row["category"]);
foreach ($categories as $category) {
// Do what you need with each $category, it will be "MEN", "CLOTHING" and "SHOES" each time
}