hi i’m new with php and i really don’t know ajax. i making a photo gallery site i used the code below to display my photos i need to make possible with ajax or any other language, when someone click on the photo in index.php with the title example:”happy day 2012″ want the photo being displayed in another page example:”photo/happy-day-2012″
<?php
$link = mysql_connect("localhost", "root","");
mysql_select_db("test", $link);
$query = "select * from post order by id DESC;";
$results = mysql_query($query, $link) or die ("error!".mysql_error());
if($results){
$i = 1;
while ($row = mysql_fetch_assoc($results)){
echo $row['title']. "<img src=/1/" . $row['location']."width=580px>"."<br/><br/><br/>";
}
}
?>
Please if possible can use lot of comments on the code.
According a previous comment, you don’t need AJAX, what you actually need is mod_rewrite.
mod_rewrite is a Apache Module, that let’s you rewrite urls according some pattern or rule.
To do this, it’s common to use .htaccess file (that should be located on your site root). If you are in a development machine, make sure you’ve enabled AllowOverride on your Apache config file.
After that you can easily do something like this
This is a very rough example, but basically what it does is… detects when a URI starts with “photo/” and send everything after that to another URL ($1 reference to what is found).
Later, you can determine on viewer.php what you want to show using $_GET[‘photo’] variable.
But again, this is pretty advanced if you are new with PHP.