2012-07-31 98 views
0

我試圖從PHPMyAdmin檢索數據,並試圖顯示數據到選擇器更改.... 這是我的代碼 var currentWin = Ti.UI.currentWindow;鈦使用JSON解析

var sendit = Ti.Network.createHTTPClient(); 
sendit.open('GET', 'http://localhost/mobileapp/productread.php'); 
sendit.send(); 
    sendit.onload = function(){ 
var json = JSON.parse(this.responseText); 

var json = json.mobile_product; 

var picker = Ti.UI.createPicker(); 
    // turn on the selection indicator (off by default) 
picker.selectionIndicator = true; 

var data = []; 
    var pos; 
data.push (Ti.UI.createPickerRow({title:''+ json[pos].product_name +  '',custom_item:'b'})); 
} 
picker.add(data); 
currentWin.add(picker); 



//var rw = db.execute("SELECT product_name, SUM(product_quantity)FROM mobile_product GROUP BY product_name"); 

picker.addEventListener('change', function(e){ 
var sendit = Ti.Network.createHTTPClient(); 
sendit.open('GET', 'http://localhost/mobileapp/orderread.php'); 
sendit.send(); 


sendit.onload = function(){ 
var json = JSON.parse(this.responseText); 

var json = json.mobile_product; 
var pos; 
var product_name = json[e.rowIndex]; 
for (pos=0; pos < json.length; pos++) { 

alert(''+json[pos].orders + ''); 
} 
} 
}) 
} 

這裏的時候,我改變選擇器,信息提示列的單個變化的所有值(訂單)...如果我改變拾取到下一個,再一次警示出現的所有DATAS在列中。例如,如果我在列(訂單)中有10個值,並且如果我更改了選擇器值,則該警報將顯示10次10​​個值。 我想根據列顯示值在選擇器中的變化.... 我已經從PHPMyAdmin檢索數據(product_name)爲picker ...當我改變選擇器,我想顯示該特定名稱的值.... 我正在使用查詢 SELECT SUM(product_quantity)作爲訂單FROM mobile_pro管GROUP BY在PHP文件PRODUCT_NAME .. 我的PHP文件是

<?php 
//cust-mysql-123-04 
$link = mysql_connect('localhost', 'root', ''); 
if (!$link) { 
die('Not connected : ' . mysql_error()); 
} 
// make foo the current db 
$db_selected = mysql_select_db('mobileapp', $link); 
if (!$db_selected) { 
die ('Can\'t use : ' . mysql_error()); 
} 
// Set the default namespace to utf8 
mysql_query("SET NAMES 'utf8'"); 
if($result = mysql_query("SELECT SUM(product_quantity) As orders FROM mobile_product  GROUP BY product_name")) { 
//echo mysql_num_rows($result); 
    while ($row=mysql_fetch_array($result)) { 
    // $json.= "<li>".$row['first_name']."</li>"; 
    $json[]=array(
    'orders'=>$row['orders'] 
    ); 
} 
} 
echo json_encode(array('mobile_product' => $json)); 

mysql_close(); 
?> 
+0

有人能幫助我在這? ?? – user1562991 2012-08-01 04:49:36

回答

0

您必須包括在SQL查詢中使用不同的值。目前,似乎只有一個聚合函數SUM(),一個靜態的GROUP語句,這就是全部。這將始終返回相同的值。

您也正在返回一個不同的列集,那麼您可能期望使用as order alius。

如果您希望返回不同的集合,則需要組裝不同的SQL SELECT語句。

考慮以下文件:

  1. This is how to prepare and execute a SQL statement against MySQL in php
  2. This function will clear many issues from the variable you pass to it
  3. Finally, you build the request with this method in Titanium.

  4. You may wish to review the following document regarding forming and consuming a GET request, as well