FAQ |
Kalender |
![]() |
#1 | ||
|
|||
Nykomling
|
Hej!
jag får bara null när jag forsöker få ut info from databas via PHP, har suttit med den tre dagar nu men lyckats ej lösa det. ![]() Kod:
<?php /* * Following code will list all the products */ // array for JSON response $response = array(); // include db connect class require_once __DIR__ . '/db_connect.php'; // connecting to db $db = new DB_CONNECT(); // get all products from products table mysql_query('SET character set utf8'); mysql_query('SET names=utf8'); mysql_query('SET character_set_client=utf8'); mysql_query('SET character_set_connection=utf8'); mysql_query('SET character_set_results=utf8'); mysql_query('SET collation_connection=utf8_general_ci'); $result = mysql_query("SELECT * FROM `gcm_users`") or die(mysql_error()); // check for empty result if (mysql_num_rows($result) > 0 ) { // looping through all results // products node $response["food"] = array(); while ($row = mysql_fetch_array($result)) { // temp user array $food = array(); $food["name"] = $result["name"]; $food["id"] = $result["id"]; // push single product into final response array array_push($response["food"], $food); } // success $response["success"] = 1; // echoing JSON response echo json_encode($response); } else { // no products found $response["success"] = 0; $response["message"] = "No food found"; // echo no users JSON echo json_encode($response); } ?> output: "food":[{"name":null,"id":null},{"name":null,"id":null},{" name":null,"id":null}],"success":1} Tack för hjälpen. MVH Agneos |
||
![]() |
![]() |
![]() |
#2 | |||
|
||||
Mycket flitig postare
|
Citat:
|
|||
![]() |
![]() |
Svara |
|
|