I am very new to PHP and I am trying to make some tutorials
I made a first small one --- creating a small database and calling some fields with php
Everything worked fine
- Code: Select all
<?php
$db = mysql_connect('localhost', 'root');
mysql_select_db('mapscripting101', $db);
$sql = "select label, latitude, longtitude from places";
$res = mysql_query($sql, $db);
while ($row = mysql_fetch_assoc($res)) {
print $row["label"];
}
mysql_close($db);
?>
The I tried a little more advanced example with the same database but I can no make it work.
Do you have any idea what can be the problem ???
- Code: Select all
<?php
$db = mysql_connect('localhost','root');
mysql_select_db('mapscripting101', $db);
$sql = "select label, latitude, longitude from places";
$res = mysql_query($sql, $db);
$allrows = array();
while ($row = mysql_fetch_assoc($res)) {
array_push($allrows, $row);
}
mysql_close($db);
print json_encode($allrows);
?>