【发布时间】:2013-04-08 15:39:14
【问题描述】:
我正在尝试进行一些文本格式化并在一大块代码中查询 SQL。以前,它没有格式化就可以很好地列出列表,但我需要用空格替换下划线并删除每个字符串之前的类别,以方便用户阅读。
<?php
//doing the query
$query = "SELECT * FROM parts WHERE itemName LIKE 'Processors:%'";
$result = mysql_query($query) or die("Unable to query parts table!");
while($row=mysql_fetch_array($result)) {
//explode removes the preceding category, str_replace obviously replaces the _
$labelCPU = explode(':',str_replace('_',' ',$row['itemName']));
//displays the option in HTML
$aa .= "<option value='{$row['partID']}'>$labelCPU</option>";
}
?>
<select name="cpu"><? echo $aa; ?></select>
当它回显列表中的变量时,我可以看出查询仍在正常执行,因为我获得了适当数量的选项,但它们都显示为“数组”。
我哪里错了?
【问题讨论】:
-
explode()返回一个数组,您将其分配给$labelCPU。你打算怎么做? -
因为你
explode()将返回数组。使用$labelCPU[0]和$labelCPU[1]等。
标签: php html mysql text-formatting