donglang6656 2013-04-05 20:11
浏览 15
已采纳

如何将信息传递到其他页面?

I have the following code which displays a table with two columns, Title and Year, when the user clicks on a title, they are sent to another page (title.php), which will give more information about that title.

echo "<table border=1>
<tr>
<th>Title</th>
<th>Year</th>
</tr>";

while ($record = mysql_fetch_array($myData)) {
    echo "<tr>";
    echo "<td><a href='title.php'>" . $record['title'] . "</a><br />" . $record['plays'] . "</td>";
    echo "<td>" . $record['year'] . "</td>";
    echo "</tr>";
}
echo "</table>";

my question is: how do i pass the title ($result['title']) from the current page to title.php?

  • 写回答

3条回答 默认 最新

  • doutan1875 2013-04-05 20:15
    关注

    In this case, you'll want to pass information using a GET variable:

    echo "<table border=1>
    <tr>
    <th>Title</th>
    <th>Year</th>
    </tr>";
    
    while ($record = mysql_fetch_array($myData)) {
        echo "<tr>";
        echo "<td><a href='title.php?title=" . $record['title'] . "'>" . $record['title'] . "</a><br />" . $record['plays'] . "</td>";
        echo "<td>" . $record['year'] . "</td>";
        echo "</tr>";
    }
    echo "</table>";
    

    Although I'd suggest passing an ID representing your primary key instead of a title so that you can grab the title after a db query on title.php

    Also, you don't need mysql_fetch_array. In this case, you only need mysql_fetch_assoc.

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

报告相同问题?

悬赏问题

  • ¥15 数学建模招标中位数问题
  • ¥15 phython路径名过长报错 不知道什么问题
  • ¥15 深度学习中模型转换该怎么实现
  • ¥15 HLs设计手写数字识别程序编译通不过
  • ¥15 Stata外部命令安装问题求帮助!
  • ¥15 从键盘随机输入A-H中的一串字符串,用七段数码管方法进行绘制。提交代码及运行截图。
  • ¥15 TYPCE母转母,插入认方向
  • ¥15 如何用python向钉钉机器人发送可以放大的图片?
  • ¥15 matlab(相关搜索:紧聚焦)
  • ¥15 基于51单片机的厨房煤气泄露检测报警系统设计