0

I'm new at php and JavaScript so I hope you can help me! below is a php code! it take data from my db and display my photos and photo's title. what I want to do is if you click on one of this photos and than a new php expe: photo.php opens and you can see the same photo alone not with the other ones.

<?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 ("you comand can't be   executed!".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 />";


}
}
?>     '
devrys
  • 1,571
  • 3
  • 27
  • 43

2 Answers2

1
<?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 ("you comand can't be   executed!".mysql_error());
if($results){
    $i = 1;
    while ($row = mysql_fetch_assoc($results)){
    //send photo_id (id of photo from your table) from url  NOTE: I've put link here
    echo $row['title']. "<a href='index.php?photo_id=".$row['id']."'><img src=/1/" . $row['location']. " width=580px ></a> " .  "<br /><br /><br />";
}
if(isset($_GET['photo_id'])) {
        //here you get only one id of photo  now retrieve the data from database and display the image  
    }
}

?>

You will get the photo by the help of the url value here photo_id.

vusan
  • 5,221
  • 4
  • 46
  • 81
0
do this way you are getting results from database and you are 
displaying them with tile and image your aim is to click on 
image or image title go to a new page and display image alone
the image title as link in first page
if($results){
$i = 1;
while ($row = mysql_fetch_assoc($results)){
<a href='new page url?id=<?php echo $row["id"] ?>'>
echo $row['title'];
echo "</a>"
}
}
where $row['id'] is database unique id if have no it is always preferred 
to create a database with unique id and in new page get the uid
 using $id=$_GET['id'] and 
do as below
if($results){
$i = 1;
while ($row = mysql_fetch_assoc($results)){
if($id==$roe['id']{
echo $row['title']. "<img src=/1/" . $row['location']. " width=580px > ";
}
}
}
Sivagopal Manpragada
  • 1,554
  • 13
  • 33