简体   繁体   English

从数据库数组中检索特定值

[英]Retrieving specific value from database array

I need to be able to bring up a list of items from the database.我需要能够从数据库中调出项目列表。 That part I have done.那部分我已经完成了。 But then I need to be able to have it so that the user can select the name of the item to go to a detail page.但是我需要能够拥有它,以便用户可以将 select 项目的名称到 go 到详细信息页面。 What I can't figure out is how to get the script to take the auction name and send that to another page.我不知道如何让脚本获取拍卖名称并将其发送到另一个页面。 What I have to pull the info is below.我必须提取的信息如下。 Not looking for someone to do it for me, just need some help figuring out how to get there.不是找人帮我做,只是需要一些帮助来弄清楚如何到达那里。

if (mysql_num_rows($result) > 0) 
{
    while ($row = mysql_fetch_array($result)) 
    {
        $aucname = $row['aucname'];
        $seller = $row['seller'];
        $price = $row['price'];
        $start = $row['start'];
        $end = $row['end'];
        $nbids = $row['nbids'];
        $category = $row['category'];

        $display_block = "Auction Name - $aucname      
                          Seller - $seller      
                          Price - $price      
                          Start Date - $start </br>
                          End Date - $end &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
                          # bids - $nbids &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
                          Category - $category <p> ------------------ </p>";
    }
    echo "$display_block";
}

Something like $link = "pagename.php?aucname=$aucname";像 $link = "pagename.php?aucname=$aucname"; will send that variable via the url.将通过 url 发送该变量。 You can also use a hidden form element to pass the data as a piece of the form.您还可以使用隐藏的表单元素将数据作为表单的一部分传递。 On the page you're passing to, this info will show up in either $_GET (for the URL iirc) or $_POST (when you pass the variable through a form that's using post).在您传递到的页面上,此信息将显示在 $_GET(对于 URL iirc)或 $_POST(当您通过使用 post 的表单传递变量时)。

The common way of doing it is to add a unique id for each row, and pass it through a $_GET variable.常见的做法是为每一行添加一个唯一的 id,并通过$_GET变量传递它。 See a skeleton example below:请参阅下面的骨架示例:

if (isset($_GET['id'])) {
   /* detailed entry 'id' */
}
else {
   /* all the entries */
   while (...)
     $display_block = '<a href="yourpage.php?id='.$row['id'].'">Auction Name...</a>';
}

If you don't want the answer then your best bet would be to look up POST and GET.如果您不想要答案,那么最好的办法是查找 POST 和 GET。 If you already can pull the information from the database then you could easily pass the object id or whatever you want to the details page and then pull the rest of the information from there.如果您已经可以从数据库中提取信息,那么您可以轻松地将 object id 或您想要的任何内容传递到详细信息页面,然后从那里提取信息的 rest。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM