Mtowns Finest Posted March 26, 2009 Share Posted March 26, 2009 Hello - I'm new to PHP, only been learning it for about a month, but I think I am starting to get the hang of it. I am working on a project that involves the Google Maps API which uses markers that are populated by values from a MySQL database. The javascript code that populates the map markers is the following. var html = '<b>' + name + '</b> <br/>' + address + '<br />' + '<a href=\"/locations/' + state + '/' + city + '/' + name + '\">View Profile</a>'; As you can see it creates a file path using the values for state, city, and name. I am now trying to write a script that runs through my database and creates the file for each row in my database. The script works when I remove the database variables, but does not work when I have it the way it currently is. I already went through the error removing process, and I now just get a black screen when I run the script, which should mean its working. Unfortunately however, the files are not created. Here is my current code. <?php ini_set('display_errors',1); error_reporting(E_ALL); $contents = 'Testing to see if this makes it onto the page'; include ('mysql_connect.php'); $query = "SELECT id, name, state, city, as sd FROM markers"; $result = @mysql_query($query); if ($result) { while ($row = mysql_fetch_assoc($result)) { $mydir = $_SERVER['DOCUMENT_ROOT'].'/locations/'; if(!empty($row['state']) && !empty($row['city']) && !empty($row['name'])){ $mydir .= $row['state'].'/'.$row['city'].'/'; if(file_exists($mydir) && is_writable($mydir)){ $mydir .= $row['name'].'.php'; // put the rest of the code to write the file here $handle = fopen($_SERVER['DOCUMENT_ROOT'].'/locations/'.$row['state'].'/'.$row['city'].'/'.$row['name'].'.php', "w") or die("Could Not Open File"); $lock = flock($handle, LOCK_EX); if ($lock){ fputs($handle, $contents); flock($handle, LOCK_UN); } fclose($handle); } } } } ?> Any help is greatly appreciated. I have looked everywhere for guides or examples that use variables in a similar way but I have had no luck. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.