Wrox Programmer Forums
Go Back   Wrox Programmer Forums > PHP/MySQL > PHP How-To
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 software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
Old June 26th, 2008, 10:55 PM
Registered User
Join Date: Jun 2008
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.
Old July 30th, 2008, 04:20 AM
Registered User
Join Date: Jul 2008
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

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

Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.