English 中文(简体)
PHP: 如何将数据结转到 Mysql 使用循环读取后的另一页
原标题:PHP: How to carry over data to another page after mysql read using while loop


I have a slight dilemma on my hands. This is the situation. On a webpage, I am using a php while loop to read data into a page from a database. That works fine but I need each of this items when clicked, go to another webpage with more info on them. This more info is just data that i will have on another column in database so its no biggie. So my dilemma is how do I know which item is clicked. Is there a way to track which unique index was clicked? (Keep in mind that I might me listing thousands of items on the page).

这是我的时空密码

while($row = mysql_fetch_array($result)){
 echo  <div class="thumb"> ;
 echo  <a href="template.php"><img src= .$row[ dresses_pic ]. /></a> ;
 echo  <p> .$row[ price_ ]. </p> ;
 echo  </div> ;
}

I have tried putting a SESSION inside the while loop but the next page always reads the last listing as the item.
Is there a better way to achieve what am trying to do?
Thanks

最佳回答

只需在链接中附加项目编号,然后从下一页上以 $_GET 变量的形式获取 :

while($row = mysql_fetch_array($result)){
 echo  <div class="thumb"> ;
 echo  <a href="template.php?id= .$row[ id ]. "><img src= .$row[ dresses_pic ]. /></a> ;
 echo  <p> .$row[ price_ ]. </p> ;
 echo  </div> ;
}

< 坚固> 模板.php

$id = (int) $_GET[ id ]; // Use this to get the item from the DB
问题回答

尝试通过行项的 ID, 然后在新页面上取回该 ID 的数据 。

 echo  <a href="template.php?id= .$row[ id ]. "><img src= .$row[ dresses_pic ]. /></a> ;

将记录代号传送到下一页(使用 URL 参数最简单, < code>?id=xxxx ),并查询 db 使用 id (您可以通过 $_GET[ id] 获得信息)。

使用查询字符串将项目 ID 传送到您的模板.php 页面 。

while($row = mysql_fetch_array($result)){
 echo  <div class="thumb"> ;
 echo  <a href="template.php?id= .$row[ item_id ]. "><img src= .$row[ dresses_pic ]. /></a> ;
 echo  <p> .$row[ price_ ]. </p> ;
 echo  </div> ;
}

参见上面修改的线条...





相关问题
CSS working only in Firefox

I am trying to create a search text-field like on the Apple website. The HTML looks like this: <div class="frm-search"> <div> <input class="btn" type="image" src="http://www....

image changed but appears the same in browser

I m writing a php script to crop an image. The script overwrites the old image with the new one, but when I reload the page (which is supposed to pickup the new image) I still see the old one. ...

Firefox background image horizontal centering oddity

I am building some basic HTML code for a CMS. One of the page-related options in the CMS is "background image" and "stretch page width / height to background image width / height." so that with large ...

Separator line in ASP.NET

I d like to add a simple separator line in an aspx web form. Does anyone know how? It sounds easy enough, but still I can t manage to find how to do it.. 10x!

热门标签