0

我是 php 和 JavaScript 的新手,所以我希望你能帮助我!下面是一个php代码!它从我的数据库中获取数据并显示我的照片和照片的标题。我想要做的是,如果您单击其中一张照片而不是新的 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 回答