Jump to content

Creating Multiple Pages


Mtowns Finest

Recommended Posts

Hello -

 

I am going to try my best to explain my project. I am using the Google Maps API with a MySQL database to populate a map. Basically a marker is created on the map for every row in the database. There is an input form that creates a new row in each database with the values it receives, these include "name", "address", "state", and "city".

 

A javascript code then populates the little info bubble that is created for each marker. It is:

var html = '<b>' + name + '</b> <br/>' + address + '<br />' + '<a href=\"/locations/' + state + '/' + city + '/' + name + '\">View Profile</a>';

 

You may notice that the variables are used to create a file path. A visual example is

visual_example.jpg

 

With an automatically generated URL I was forced to automatically create an file for that URL to find.

For this, I tried using the fopen function, my code was

<?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 = '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

// next line is wrong because state, city and name is already in mydir
// $handle = fopen($mydir.$row['state'].'/'.$row['city'].'/'.$row

['name'].'.php', "w") or die("Could Not Open File"); 
// must be:
$handle = fopen($mydir, "w") or die("Could Not Open File");  
  

$lock = flock($handle, LOCK_EX);  

if ($lock){ 
fputs($handle, $contents);  
flock($handle, LOCK_UN);  
}  
fclose($handle); 
}} 
}}  

 

This, unfortunantly, does nothing for me. I fixed all of the errors, and now get a blank page when I run, so it should be working, however it creates no files in the locations. I have asked on multiple forums, and no one can tell me why it isnt working. So after turning my hair grey with this method for the last 2 days, I need to throw the towel in on it an find a method that does work. I have searched everywhere for methods, but cannot find any guides or examples, so I am guessing it is pretty basic stuff.

 

If anyone has any ideas or methods that would solve this task I could really use them. Even if you just point me towards a guide that would be greatly apreciated. The closest I found was http://www.codingforums.com/archive/index.php/t-107879.html, but it doesnt explain anything so I couldnt work with it.

 

Thanks

Link to comment
https://forums.phpfreaks.com/topic/151329-creating-multiple-pages/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.