Expecto
Expecto

Reputation: 521

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 - $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";
}

Upvotes: 1

Views: 292

Answers (3)

patapizza
patapizza

Reputation: 2398

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>';
}

Upvotes: 1

Tyler Ferraro
Tyler Ferraro

Reputation: 3772

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.

Upvotes: 0

Chad
Chad

Reputation: 364

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).

Upvotes: 2

Related Questions