我試圖做一個小文本格式和查詢SQL在一個代碼塊。此前,它在做上市就好了,不進行格式化,但我需要用空格來代替下劃線,並刪除每個字符串爲用戶提高可讀性之前的類別。PHP保持顯示「數組」,而不是[字符串]
<?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>
當迴響在列表中的變量,我可以告訴查詢仍在執行很好,因爲我得到的選項中選擇合適的數字,但它們都顯示爲「陣列」。
我在哪裏錯了?
'爆炸()'返回一個數組,其中分配給'$ labelCPU'。你打算怎麼做? – 2013-04-08 15:40:54
因爲'explode()'會返回數組。使用'$ labelCPU [0]'和'$ labelCPU [1]'等等 – 2013-04-08 15:43:49