doufutao4428 2013-03-31 18:30
浏览 6
已采纳

通过单击行的标题链接显示表的整行?

The thing I want to is like the job done in many news websites. Suppose I have a table of news. Each news have title and full text. So I want to show the news in a page. I want to limit the news displayed in a page to for example three news per page (using the limit query which is easy) and I want to show only the titles. But I want the titles to be a link to the full text news. I mean when a user clicks on it, a new page shows up with the full text of that news. So what should I do?

  • 写回答

2条回答 默认 最新

  • dongyan1899 2013-03-31 19:19
    关注

    news_titles.php:

     <?php
     //connection; then simple mysql_query and fetch (mysql is deprecated, so reconstruct it with another lib
     $sql = "SELECT id, news_content, news_title FROM news;";
     $result = mysql_query($sql);
     while ($row = mysql_fetch_assoc($result)) {
        ?>
      <a href="news.php?id=<?=$row['id']; ?>"><?= $row['news_title']; ?></a>
     <?php
    
     }   
     ?>
    

    then create news.php:

     <?php
     //connection; then simple mysql_query and fetch (mysql is deprecated, so reconstruct it with another lib
     $sql = "SELECT id, news_content, news_title FROM news WHERE id = ". $_GET['id'] . ";";
     $result = mysql_query($sql);
     while ($row = mysql_fetch_assoc($result)) {
       ?>
     <p><?= $row['news_content']; ?>
     <?php
    
      }
     ?>
    

    It will create you hyperlinks with news title's leading to news id and showing news_content in it. It will access news.php via i.e. news.php?id=5

    If you get the idea, you may change some things for more security, clean and fresh code, and design

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 keil的map文件中Image component sizes各项意思
  • ¥30 BC260Y用MQTT向阿里云发布主题消息一直错误
  • ¥20 求个正点原子stm32f407开发版的贪吃蛇游戏
  • ¥15 划分vlan后,链路不通了?
  • ¥20 求各位懂行的人,注册表能不能看到usb使用得具体信息,干了什么,传输了什么数据
  • ¥15 Vue3 大型图片数据拖动排序
  • ¥15 Centos / PETGEM
  • ¥15 划分vlan后不通了
  • ¥20 用雷电模拟器安装百达屋apk一直闪退
  • ¥15 算能科技20240506咨询(拒绝大模型回答)