我在這裏有一個非常非常奇怪的問題。我有數據在php中的數組。我想要爲數組查詢數據庫並獲取結果的每個項目。它只顯示我具體的結果,而不是一切。陣列打印數據正確,但查詢只顯示一半
我的代碼:
foreach($my as $k=> $v){
//echo "Key: ". $k . " Value: " . $v . "<br/>";
$sql2 = "SELECT column10 FROM `table` WHERE column1 = '$v' ";
$res2 = mysql_command($sql2);
echo $sql2 . "<br/>";
$rowA = mysql_fetch_assoc($res2);
//echo "<strong>Alternative: </strong>" . $v. "<strong> Auto Alternative: </strong>" . $rowA['column10'] . "<br/>";
}
echo '</table>';
echo "<pre>";
print_r($my);
echo "</pre>";
在瀏覽器中的結果,如果我回應查詢和密鑰:和值是這樣的:
SELECT column10 FROM `table` WHERE column1 = 'Villetta La Canoa'
SELECT column10 FROM `table` WHERE column1 = ' Casa Immerso nel Verde'
SELECT column10 FROM `table` WHERE column1 = ' La Rosetta'
SELECT column10 FROM `table` WHERE column1 = 'Agriturismo La Nonna'
SELECT column10 FROM `table` WHERE column1 = ' Villetta Cassiopeia'
SELECT column10 FROM `table` WHERE column1 = ' La Rosetta'
SELECT column10 FROM `table` WHERE column1 = 'Ca Gianca 2'
SELECT column10 FROM `table` WHERE column1 = ' Villetta Teresa'
SELECT column10 FROM `table` WHERE column1 = ' Appartamento Pinamare'
SELECT column10 FROM `table` WHERE column1 = ' Casa del Principe'
SELECT column10 FROM `table` WHERE column1 = 'Ca Gianca 2'
SELECT column10 FROM `table` WHERE column1 = ' Villetta Teresa'
SELECT column10 FROM `table` WHERE column1 = ' Appartamento Pinamare'
SELECT column10 FROM `table` WHERE column1 = ' Casa del Principe'
SELECT column10 FROM `table` WHERE column1 = 'Ca Gianca 2'
SELECT column10 FROM `table` WHERE column1 = ' Villetta Teresa'
SELECT column10 FROM `table` WHERE column1 = ' Appartamento Pinamare'
SELECT column10 FROM `table` WHERE column1 = ' Casa del Principe'
的關鍵價值是:
Key: 0 Value: Villetta La Canoa
Key: 1 Value: Casa Immerso nel Verde
Key: 2 Value: La Rosetta
Key: 3 Value: Agriturismo La Nonna
Key: 4 Value: Villetta Cassiopeia
Key: 5 Value: La Rosetta
Key: 6 Value: Ca Gianca 2
Key: 7 Value: Villetta Teresa
Key: 8 Value: Appartamento Pinamare
Key: 9 Value: Casa del Principe
Key: 10 Value: Ca Gianca 2
Key: 11 Value: Villetta Teresa
Key: 12 Value: Appartamento Pinamare
Key: 13 Value: Casa del Principe
Key: 14 Value: Ca Gianca 2
Key: 15 Value: Villetta Teresa
Key: 16 Value: Appartamento Pinamare
Key: 17 Value: Casa del Principe
我得到的是:
Alternative: Villetta La Canoa Auto Alternative: Villa Ronchi, Casa Ciserai, Villino Torretta, Casa Bianca
Alternative: Casa Immerso nel Verde Auto Alternative:
Alternative: La Rosetta Auto Alternative:
Alternative: Agriturismo La Nonna Auto Alternative: Agriturismo Antico Granaio, Casa Ciserai, Villa Ronchi, La Rosetta
Alternative: Villetta Cassiopeia Auto Alternative:
Alternative: La Rosetta Auto Alternative:
Alternative: Ca Gianca 2 Auto Alternative: Ca Gianca 1, La Vigna 2, Villetta Teresa
Alternative: Villetta Teresa Auto Alternative:
Alternative: Appartamento Pinamare Auto Alternative:
Alternative: Casa del Principe Auto Alternative:
Alternative: Ca Gianca 2 Auto Alternative: Ca Gianca 1, La Vigna 2, Villetta Teresa
Alternative: Villetta Teresa Auto Alternative:
Alternative: Appartamento Pinamare Auto Alternative:
Alternative: Casa del Principe Auto Alternative:
Alternative: Ca Gianca 2 Auto Alternative: Ca Gianca 1, La Vigna 2, Villetta Teresa
Alternative: Villetta Teresa Auto Alternative:
Alternative: Appartamento Pinamare Auto Alternative:
Alternative: Casa del Principe Auto Alternative:
任何人都可以解釋什麼是錯的?
您好,首先提示的全部cople的,'mysql_ *'功能過時,你應該改變爲'mysqli'或''PDO,你應該給DB列更多descripive名稱,它可以是一個噩夢保持或理解該代碼:) – Asur
它顯示你'SELECT column10',而不是'SELECT *'? – devpro
'mysql_command'到底是什麼? –