|
(X)HTML, JavaScript, DHTML, XML, CSS Client scripting tehnologije, Dynamic HTML, Cascading Stylesheets, XML i standardi |
|
Alati teme | Način prikaza |
|
04. 02. 2014. | #1 |
emperor Selassie
Grand Master
|
U svakom programskom jeziku postoji 10 načina da odradiš istu stvar. Umesto MySQL funkcija koristi MySQLi na primer: http://php.net/mysqli
Poslednja izmena od Nemanja Avramović : 04. 02. 2014. u 08:14. Razlog: mysqli link |
04. 02. 2014. | #2 | |
profesionalac
Professional
Datum učlanjenja: 25.10.2012
Poruke: 278
Hvala: 16
32 "Hvala" u 9 poruka
|
Citat:
Kôd:
$mysqli =mysqli_connect('localhost', 'baza', 'pass', 'korisnik'); if (mysqli_connect_errno()) { echo "Failed to connect to MySQL: ".mysqli_connect_error(); } $query = mysqli_query($mysqli, 'SELECT * FROM stat'); if (!$query) { die("Error running $sql: " . mysql_error()); } $table = array(); $table['cols'] = array( array('label' => 'ID', 'type' => 'number'), array('label' => 'Name', 'type' => 'string'), array('label' => 'Gender', 'type' => 'string'), array('label' => 'Age', 'type' => 'number'), array('label' => 'Donuts eaten', 'type' => 'number') ); $rows = array(); while($r = mysqli_fetch_assoc($query)) { $temp = array(); // each column needs to have data inserted via the $temp array $temp[] = array('v' => (int) $r['ID']); $temp[] = array('v' => $r['Name']); $temp[] = array('v' => $r['Gender']); $temp[] = array('v' => (int) $r['Age']); $temp[] = array('v' => (int) $r['Donuts eaten']); // typecast all numbers to the appropriate type (int or float) as needed - otherwise they are input as strings // insert the temp array into $rows $rows[] = array('c' => $temp); } // populate the table with rows of data $table['rows'] = $rows; // encode the table as JSON $jsonTable = json_encode($table); echo $jsonTable; |
|
|
|