Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > PHP/MySQL > PHP How-To
Password Reminder
| FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
PHP How-To Post your "How do I do this with PHP?" questions here.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the PHP How-To section of the Wrox Programmer to Programmer discussions. This is a community of tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old June 26th, 2008, 10:55 PM
Registered User
Join Date: Jun 2008
Location: , , Portugal.
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
Default How to associate table rows with hyperlink?[READ]

Hi. I have a table listing products' data that is retrieved from the database. Each row corresponds to a product, and at the end of each row, there is a "buy" hyperlink. Each row is generated through a "for" loop like this:


if(!$connection){die(' ' . mysql_error());}

die(' ' . mysql_error());

$query=mysql_query("SELECT * FROM products",$connection);

$data = mysql_fetch_assoc($query);
$query_image=mysql_query("SELECT * FROM images",$connection);
$image = mysql_fetch_assoc($query_image);
echo "<tr align=center> <td>".$data['name']."</td>";
echo "<td>".$data['label']."</td>";
echo "<td>".$data['price']." €</td>";
echo "<td>".$data['stock_quantity']."</td>";
echo "<td><img scr='".$image['path']."'></td>";
echo "<td align=right><a href='product_reservation.php' name='link'>Buy</a></td>";
echo "</tr>";}
What I wanted it to do when the user clicked on the buy hyperlink was to generate a prompt so that the user could input the desired quantity of the product in the same row as the hyperlink. Then, the product_id, the quantity, the price*quantity and the user_id would all be stored in a relational table called "Orders" with foreign keys from the products' table and the users' table. All of that would be in the file "product_reservation.php" that is referenced by the hyperlink.

I thought of something like setting the name of each hyperlink to the current value of the $i variable (see in the for statement) and then relate it to the number of the product in its table, as this is listed in order. Such as this:

1st product in table - "Garments" -> $i=1
hyperlink name="1"

And then relate them in some way. Is something like this possible?

Please, please give suggestions and help.
Reply With Quote
  #2 (permalink)  
Old July 30th, 2008, 04:20 AM
Registered User
Join Date: Jul 2008
Location: Leeds, , United Kingdom.
Posts: 8
Thanks: 0
Thanked 0 Times in 0 Posts

in your href, put all the details you need

e.g. <a href='yourpage.php?id=1'>Buy</a>

then in the processing page, you can retrieve the values by accessing $_GET

Reply With Quote

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
Read CSV file - Save Columns into Rows pintoo BOOK: Professional SQL Server 2005 Integration Services ISBN: 0-7645-8435-9 1 August 20th, 2008 09:01 AM
Read all rows from text file shai505 C# 5 April 28th, 2006 09:37 PM
Comparing certain rows in one table MrHicks Access 2 November 8th, 2004 04:00 PM
Hyperlink in a cell table amc Dreamweaver (all versions) 33 August 5th, 2004 12:11 PM
Q:Read two rows from table LegoMan ASP.NET 1.0 and 1.1 Basics 4 October 14th, 2003 01:22 PM

All times are GMT -4. The time now is 10:25 PM.

Powered by vBulletin®
Copyright ©2000 - 2019, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.