开发者

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. 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 - 开发者_StackOverflow社区$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"; will send that variable via the 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).


The common way of doing it is to add a unique id for each row, and pass it through a $_GET variable. 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. 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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜