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:
Code:
Code:
$connection=mysql_connect('localhost','root',');
if(!$connection){die(' ' . mysql_error());}
$bd=mysql_select_db('PAT',$connection);
if(!$bd){
die(' ' . mysql_error());
}
$query=mysql_query("SELECT * FROM products",$connection);
$regists=mysql_num_rows($query);
for($i=1;$i<=$regists;$i++){
$data = mysql_fetch_assoc($query);
$query_image=mysql_query("SELECT * FROM images",$connection);
$image = mysql_fetch_assoc($query_image);
if($data['reserved']!=1){
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.