انجمن سایت کلیدستان


رتبه موضوع:
  • 0 رای - 0 میانگین
  • 1
  • 2
  • 3
  • 4
  • 5
jsonparser

jsonparser

#1
باسلام .. کد نویسی اندروید رو مطابق اموزش http://www.kelidestan.com/keys/keys.php?key=2651
پیش رفتم و نوشتم ولی مشکلم توی کد های php  هست .. من از این کد استفاده میکنم ولی توی برنامه نهایی فقط اولین ردیف جدول رونشون میده 
اینا کد php
کد پی‌اچ‌پی:
<?php

$con
=mysql_connect("localhost","ysrcv_momayyezi","Mo137171");
mysql_select_db(ysrcv_travel,$con);

$response=array();
$result=mysql_query("select * from travel");

if(
mysql_num_rows($result)>0){
$temp=array();
    while(
$row=mysql_fetch_array($result)){
        
        
$temp["companyname"]=$row["companyname"];
        
$temp["cod"]=$row["cod"];
        
$temp["bign"]=$row["bign"];
        
$temp["stop"]=$row["stop"];
        
$temp["date"]=$row["date"];
        
$temp["time"]=$row["time"];
        
$temp["price"]=$row["price"];
        
        
$response["travel"]=array();
        
array_push($response["travel"],$temp);
    
$response["t"]=1;
    echo 
json_encode($response);

    
    }
    
}else{
    
$response["t"]=0;
    
$response["message"]="not fonud";
    echo 
json_encode($response);
    
}
?>
 و این هم کد های سمت اندروید: 
کد:
@Override
       protected String doInBackground(String... argman) {
         // ContentValues params = new ContentValues();
       List<NameValuePair> params = new ArrayList<NameValuePair>(); // Building Parameters

           // getting JSON string from URL
           JSONObject json = jparser.makeHttpRequest(url, "GET", params);


           try {
               int t = json.getInt("t");

               if (t==1){
                   s=json.getJSONArray("travel");
                   for (int i=0;i<s.length();i++){
                       JSONObject c=s.getJSONObject(i);
                       String companyname=c.getString("companyname");
                       String cod=c.getString("cod");
                       String time=c.getString("time");
                       String date=c.getString("date");
                       String bign=c.getString("bign");
                       String stop=c.getString("stop");
                       String price=c.getString("price");

                       HashMap<String,String> map=new HashMap<String,String>();
                       map.put("companyname",companyname);
                       map.put("cod",cod);
                       map.put("time",time);
                       map.put("date",date);
                       map.put("bign",bign);
                       map.put("stop",stop);
                       map.put("price",price);

                       P.add(map);


                   }


               }else {
                   Toast.makeText(MainActivity.this,"لطفا اظلعاددد",Toast.LENGTH_SHORT).show();
               }


           } catch (JSONException e) {
               e.printStackTrace();

                  }


           return null;
       }

لطفا راهنماییم کنید مشکل کد های php  کجاست
پاسخ
 سپاس شده توسط شماره مجازی امارات


پرش به انجمن:


کاربران در حال بازدید این موضوع: 1 مهمان