Mysql
 sql >> Teknologi Basis Data >  >> RDS >> Mysql

Tidak dapat mengambil data dari tabel MySQL yang cocok dengan uid tertentu

Di aplikasi Android, Anda mengharapkan JSONArray:

// store incoming stream in an array
JSONArray jArray = new JSONArray(streamToString(instream));

Namun, dalam file PHP Anda, Anda hanya menampilkan beberapa objek JSON terpisah alih-alih array nyata. Saya pikir, Anda harus mengumpulkan semua item dari database dalam array PHP terlebih dahulu dan kemudian menyandikan dan mengeluarkannya hanya sekali.

Keterampilan PHP saya agak berkarat, tapi saya harap ini akan berhasil:

//store # of rows returned
$num_rows = mysql_num_rows($query);

if ($num_rows >= 1) {
    $output = array();

    while($results = mysql_fetch_assoc($query)) {
        // append row to output
        $output[] = results
    }

    mysql_close();  // shouldn't that be outside the if block?

    //encode the returned data in JSON format
    echo json_encode($output);
}

Saya berharap hasilnya akan seperti ini (mungkin tanpa lekukan):

[
    {"nid":"1","vid":"1","type":"goal","language":"","title":"test","uid":"1","status":"1","created":"1342894493","changed":"1342894493","comment":"2","promote":"1","moderate":"0","sticky":"1","tnid":"0","translate":"0"},
    {"nid":"2","vid":"2","type":"goal","language":"","title":"test2","uid":"1","status":"1","created":"1342894529","changed":"1342894529","comment":"2","promote":"1","moderate":"0","sticky":"1","tnid":"0","translate":"0"},
    {"nid":"5","vid":"5","type":"goal","language":"","title":"run","uid":"1","status":"1","created":"1343506987","changed":"1343506987","comment":"2","promote":"1","moderate":"0","sticky":"1","tnid":"0","translate":"0"},
    {"nid":"9","vid":"9","type":"goal","language":"","title":"run to the hills","uid":"1","status":"1","created":"1343604338","changed":"1343605100","comment":"2","promote":"0","moderate":"0","sticky":"0","tnid":"0","translate":"0"}
]


  1. Database
  2.   
  3. Mysql
  4.   
  5. Oracle
  6.   
  7. Sqlserver
  8.   
  9. PostgreSQL
  10.   
  11. Access
  12.   
  13. SQLite
  14.   
  15. MariaDB
  1. Symfony 3.4 Tidak Ada Kelas Metadata untuk memproses Kesalahan

  2. Koneksi tanpa DSN ke server mysql di ms-access tidak mengingat nama pengguna dan kata sandi

  3. Mengambil koordinat tipe titik MySQL

  4. Menggunakan sqlalchemy untuk kueri menggunakan beberapa kolom di mana dalam klausa

  5. java.net.ConnectException:gagal terhubung ke localhost/127.0.0.1 (port 80):koneksi gagal:ECONNREFUSED (Koneksi ditolak)