dongwuge6201 2015-04-16 13:14
浏览 298
已采纳

阅读更多按钮

I have the below table in my site... enter image description here and what I want is that when i click on the read more link to redirect me to the page view_announcement.php and in this page to display me the whole data for this specific row. For example, if we click on the link in the second row I want in the view_announcement.php to load all the data for this specific row.

My code in order to display this table is this...

<?php
$q = ($_GET['q']);

$con = mysqli_connect('localhost','root','smogi','project');
if (!$con) {
    die('Could not connect: ' . mysqli_error($con));
}

mysqli_select_db($con,"project");
$sql="SELECT author,category,subject,content FROM announcements WHERE category = '".$q."'";
$result = mysqli_query($con,$sql);

echo "<table>
<tr>
<th>Author</th>
<th>Category</th>
<th>Subject</th>
<th>Content</th>

</tr>";
while($row = mysqli_fetch_array($result)) {
    echo "<tr>";
    echo "<td>" . $row['author'] . "</td>";
    echo "<td>" . $row['category'] . "</td>";
    echo "<td>" . $row['subject'] . "</td>";
    echo "<td>" . '<a href="view_announcement.php">Read More</a>' . "</td>";
    echo "</tr>";
}
echo "</table>";
mysqli_close($con);
?>

The view_announcement.php file doesn't contain any code yet because i dont know what to write.

  • 写回答

2条回答 默认 最新

  • dongzhouzhang8696 2015-04-16 15:41
    关注

    One way to do it is to append a query variable to the "Read More" links. You'll probably need a unique identifier, such as an ID number, on your announements table. If you don't have one yet, I suggest adding one and setting it up to auto-increment.

    You would want to modify your query to include the unique ID number:

    $sql="SELECT id,author,category,subject,content FROM announcements WHERE category = '".$q."'";
    

    Then you would modify the loop which prints your table out to include those unique IDs in the URL to view_announcement.php

    while($row = mysqli_fetch_array($result)) {
        echo "<tr>";
        echo "<td>" . $row['author'] . "</td>";
        echo "<td>" . $row['category'] . "</td>";
        echo "<td>" . $row['subject'] . "</td>";
        echo "<td>" . '<a href="view_announcement.php?id='.$row['id'].'">Read More</a>' . "</td>";
        echo "</tr>";
    }
    

    And in your file view_announcement.php, you would make another SQL query to get the full data for a specific row, like this:

    $sql="SELECT * FROM announcements WHERE ID = '".$_GET['id']."'";
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥60 求一个简单的网页(标签-安全|关键词-上传)
  • ¥35 lstm时间序列共享单车预测,loss值优化,参数优化算法
  • ¥15 基于卷积神经网络的声纹识别
  • ¥15 Python中的request,如何使用ssr节点,通过代理requests网页。本人在泰国,需要用大陆ip才能玩网页游戏,合法合规。
  • ¥100 为什么这个恒流源电路不能恒流?
  • ¥15 有偿求跨组件数据流路径图
  • ¥15 写一个方法checkPerson,入参实体类Person,出参布尔值
  • ¥15 我想咨询一下路面纹理三维点云数据处理的一些问题,上传的坐标文件里是怎么对无序点进行编号的,以及xy坐标在处理的时候是进行整体模型分片处理的吗
  • ¥15 CSAPPattacklab
  • ¥15 一直显示正在等待HID—ISP