0

私はphpとJavaScriptが初めてなので、助けていただければ幸いです!以下はphpコードです!データベースからデータを取得し、写真と写真のタイトルを表示します。私がやりたいのは、この写真の 1 つをクリックすると、新しい php expe: photo.php が開き、他の写真ではなく同じ写真だけを見ることができるということです。

<?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 />";


}
}
?>     '
4

2 に答える 2

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  
    }
}

?>

ここの URL 値を使用して写真を取得しますphoto_id

于 2012-10-02T10:35:46.803 に答える
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 > ";
}
}
}
于 2012-10-02T11:08:23.430 に答える