0

PHPMyAdmin からデータを取得しようとしていて、データをピッカーの変更に表示しようとしています.... これが私のコードです var currentWin = Ti.UI.currentWindow;

 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 + '');
}
}
})
 }

ここで、ピッカーを変更すると、単一の変更に対する列 (注文) のすべての値を含むアラートが表示されます...ピッカーを次のものに変更すると、列内のすべてのデータに対して再びアラートが表示されます..たとえば、列(順序)に10個の値があり、ピッカー値を変更すると、10個の値でアラートが10回表示されます.ピッカーの変更に応じて列から値を表示したい...ピッカーの PHPMyAdmin から data(product_name) を取得しました... ピッカーを変更するとき、その特定の名前の値を表示したいです.... クエリ SELECT SUM(product_quantity) As orders FROM を使用していますPHPファイルのmobile_product GROUP BY 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();
?>
4

1 に答える 1

0

SQLクエリで使用するには、別の値を含める必要があります。現在、集約関数SUM()、静的GROUPステートメントのみが存在するようであり、それだけです。これは常に同じ値を返します。

また、別の列セットを返す場合は、おそらく注文としてのアリウスを使用することを期待します。

別のセットを返す場合は、別のSQLSELECTステートメントをアセンブルする必要があります。

次のドキュメントを検討してください。

  1. これは、PHPでMySQLに対してSQLステートメントを準備して実行する方法です。
  2. この関数は、渡した変数から多くの問題をクリアします
  3. 最後に、Titaniumでこのメソッドを使用してリクエストを作成します。

  4. GETリクエストの作成と使用についても、次のドキュメントを確認することをお勧めします。

于 2013-03-07T05:17:19.573 に答える