WN

WN (https://www.wn.se/forum/index.php)
-   Serversidans teknologier (https://www.wn.se/forum/forumdisplay.php?f=4)
-   -   behöver hjälp med mySQL och PHP (https://www.wn.se/forum/showthread.php?t=1065676)

agneos 2015-10-04 17:43

behöver hjälp med mySQL och PHP
 
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.

http://i58.tinypic.com/316nes5.png
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

yakuzaemme 2015-10-04 17:48

Citat:

$food["name"] = $result["name"];
$food["id"] = $result["id"];
Byt ut result mot row


Alla tider är GMT +2. Klockan är nu 01:32.

Programvara från: vBulletin® Version 3.8.2
Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Svensk översättning av: Anders Pettersson