2017-05-30 132 views
0

我希望從我的數據庫中獲取數據並將其插入到數組中以將其傳遞給我的Android應用程序。數據加以取出:PHP使用fetch()獲取值

小屋都是預製造的結構中,符合生態旅遊的嚴格規範,以便保持森林覆蓋的原始字符和堅固性。隨着汽車停下來,你會發現自己坐落在一個溫柔的山坡上,在厚厚的橡樹和松樹下。歡迎來到西姆拉最好的度假勝地Shoghi的Aamod。 Aamod Shoghi的另一個祕訣就是我們的麪包店。新鮮出爐的好吃的香氣會喚醒你每一個清醒的時刻。如果您要求我們收拾幾個分類以帶回家,我們不會感到驚訝。我們自稱是所有西姆拉餐廳最好的麪包師。 Aamod的一天永遠不會沒有任何行動。清晨打開窗戶,欣賞壯麗的景色和清新的空氣。隨着這一切開始,你的一天充滿了驚喜。在我們廣闊的草坪上享用團隊早餐,或在我們衆多的設施的幫助下玩有趣的團隊建設遊戲。您可以在我們寬敞的會議室中安排商務活動。當你的團隊忙於團隊建設活動時,你可以在我們專業維護的小鏟和果嶺上策劃下一場領先的高爾夫球比賽!

但腳本每次崩潰。

$resort_name = $_POST['resort_name']; 

$sql = "SELECT resort_desc from resorts where resort_name = :resort_name"; 
$stmt = $conn->prepare($sql); 
$stmt->bindParam(':resort_name', $resort_name, PDO::PARAM_STR); 
$stmt->execute(); 
if($stmt->rowCount()){ 
    $response["resort_desc"] = array(); 
    $response["resort_desc"][0] = $stmt->fetch(); 
    $response["success"] = 1; 
} else { 
    $response["success"] = 0; 
} 

結果的大小是否太大?如果是的話,我怎麼能得到這些數據?

的var_dump( '響應') `

array(1) { 
    array(2) { 
    ["resort_desc"]=> 
    string(1135) "The cottages are all pre-fabricated structures in-line with the strict norms of Ecotourism so as to retain the original character and ruggedness of the forest cover. As the car stops, you�ll find yourself on a gentle hill slope, under a thick cover of oak and pine trees. Welcome to Aamod at Shoghi, the finest resort of Shimla. Another of our best kept secrets at Aamod Shoghi is our bakery. The aroma of freshly baked goodies will entice you every waking hour. We won�t be surprised if you ask us to pack a few assortments to carry back home. We claim to be the best bakers in all of Shimla restaurants. A day at Aamod is never without action. Open your windows early morning for a majestic view and fresh air. And with this begins your day full of surprises. Have team breakfast in our sprawling lawns or play interesting team building games with the help of our multitude of facilities. You can have Business retreats in our spacious conference rooms. While your team is busy at team building activities you can plan your next leadership retreat over a game of golf on our professionally maintained chipping and putting greens!" 

    string(1135) "The cottages are all pre-fabricated structures in-line with the strict norms of Ecotourism so as to retain the original character and ruggedness of the forest cover. As the car stops, you�ll find yourself on a gentle hill slope, under a thick cover of oak and pine trees. Welcome to Aamod at Shoghi, the finest resort of Shimla. Another of our best kept secrets at Aamod Shoghi is our bakery. The aroma of freshly baked goodies will entice you every waking hour. We won�t be surprised if you ask us to pack a few assortments to carry back home. We claim to be the best bakers in all of Shimla restaurants. A day at Aamod is never without action. Open your windows early morning for a majestic view and fresh air. And with this begins your day full of surprises. Have team breakfast in our sprawling lawns or play interesting team building games with the help of our multitude of facilities. You can have Business retreats in our spacious conference rooms. While your team is busy at team building activities you can plan your next leadership retreat over a game of golf on our professionally maintained chipping and putting greens!" 
    } 
} 
["success"]=> 
int(1) 
} 
+0

你是什麼意思的崩潰?是否顯示任何錯誤? – Anton

+0

沒有數據傳回。我檢查了郵差。使用var_dump($ _ POST)我可以看到數據已通過,但沒有回顯。 @Anton –

+0

在這個腳本中,你如何將數據傳遞給Android應用程序..? – CoderSam

回答

0

當你使用它$stmt->fetch()返回結果集,而不是一個單獨的值。 所以做一些像

$data = $stmt->fetch(); 
$response["resort_desc"][0] = $data["resort_desc"]; 
+0

試過沒有變化:( –

+0

你可以刪除[0],因爲這可能是不需要的,還有設置'$ response [「resort_desc」] = array( );'。 –

+0

完成它:) @Nigel –