bjorn2404 / jQuery-Store-Locator-Plugin

A store locator plugin using Google Maps API version 3
MIT License
495 stars 235 forks source link

PHP #16

Closed ghost closed 11 years ago

ghost commented 11 years ago

Hey Bjorn,

I'm getting this error message when I use your php to fetch the data from the database:

Connected to MySQL

Warning: mysql_fetch_assoc() expects parameter 1 to be resource, boolean given in /home/topspots/public_html/smilemagic/locations.php on line 17 []


Here is the code I'm using:

<?php $username = "_"; $password = "_"; $hostname = "localhost";

//connection to the database $dbhandle = mysql_connect($hostname, $username, $password) or die("Unable to connect to MySQL"); echo "Connected to MySQL
";

$results = mysql_query('SELECT * FROM locations'); $rows = array(); while($r = mysql_fetch_assoc($results)) { $rows[] = $r; } echo json_encode($rows);

?>

Please help,

Thanks!

bjorn2404 commented 11 years ago

You need to select the database before doing the query. You could use mysql_select_db($db,$dbhandle); and set the $db variable above with your other settings or you could use a mysqli connection if your server supports it.

ghost commented 11 years ago

Ok great! I was able to connect, thank you! I'm also a little confused because on your blog it says to just set the "dataLocations" setting to the php file, but in the Json example you're setting it to a location.json file. How are you pulling the data into the json file that the php file renders?

bjorn2404 commented 11 years ago

I just copied the source from the browser and pasted it into a file for the example. If you read above the screenshot: "The JSON file included in the GitHub repository is just there as an example. The file was generated via PHP from a MySQL database."

bjorn2404 commented 11 years ago

Also, if you've downloaded 1.4.9 be sure to use name instead of locname in your locations table.

ghost commented 11 years ago

Ok thanks!