2012-07-31 4 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)를 검색했습니다 ... 피커를 변경할 때 해당 특정 이름의 값을 표시하고 싶습니다 .... 쿼리 SELECT SUM (product_quantity) FROM mobile_pro 덕트 그룹은 PHP 파일에서 제품 _ 에 의해 .. 내 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

답변

0

당신은 SQL 쿼리에 사용되는 다른 값을 포함해야 할 것이다. 현재, 집계 함수 SUM(), 정적 GROUP 문만있는 것처럼 보입니다. 이것은 항상 같은 값을 반환합니다.

또한 다른 열 세트를 반환하면 사용자는 as 명령을 사용하려고합니다.

다른 집합을 반환하려는 경우 다른 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

관련 문제