getting record id from data displayed in html table

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
User avatar
aceconcepts
DevNet Resident
Posts: 1424
Joined: Mon Feb 06, 2006 11:26 am
Location: London

getting record id from data displayed in html table

Post by aceconcepts »

Hi,

I have displayed some data in a table from a product table stored in mysql database.

I have an additional column that will allow me to update the stock qty in mysql database.

How do i update that specific redord?
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

use a hidden form field?

You're awefully vague on the implementation of your "table" so it's hard to say anything for sure. :?
User avatar
aceconcepts
DevNet Resident
Posts: 1424
Joined: Mon Feb 06, 2006 11:26 am
Location: London

Post by aceconcepts »

feyd | Please use

Code: Select all

and

Code: Select all

tags where appropriate when posting code. Read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url][/color]


Hi,

Here is the code that makes up the table display:

Code: Select all

$query = "SELECT * FROM product";

$result = mysql_query($query, $link)
	or die(mysql_error());
$num_orders = mysql_num_rows($result);

$product_header =<<<EOD
<table width="760" height="25">
<tr bgcolor="#CACFE3">
	<th><font color="#000066" size="2" face="Verdana, Arial, Helvetica, sans-serif"><strong><center>Product List</center></strong></font></th>
</tr>
</table>
<table width="760" border="0" cellpadding="1"
	cellspacing="1" align="left">
	<tr bgcolor="#000066">
	<th width="60"><font color="#FFFFFF" size="2" face="Verdana, Arial, Helvetica, sans-serif"><strong>ID</strong></font></th>
	<th width="70" align="center"><font color="#FFFFFF" size="2" face="Verdana, Arial, Helvetica, sans-serif"><strong>Code</strong></font></th>
	<th width="70" align="center"><font color="#FFFFFF" size="2" face="Verdana, Arial, Helvetica, sans-serif"><strong>Name</strong></font></th>
	<th width="70" align="center"><font color="#FFFFFF" size="2" face="Verdana, Arial, Helvetica, sans-serif"><strong>Desc</strong></font></th>
	<th width="80" align="center"><font color="#FFFFFF" size="2" face="Verdana, Arial, Helvetica, sans-serif"><strong>Qty p/p</strong></font></th>
	<th width="50" align="center"><font color="#FFFFFF" size="2" face="Verdana, Arial, Helvetica, sans-serif"><strong>Qty e/a/p/p</strong></font></th>
	<th width="50" align="center"><font color="#FFFFFF" size="2" face="Verdana, Arial, Helvetica, sans-serif"><strong>Cost p/p</strong></font></th>	
	<th width="50" align="center"><font color="#FFFFFF" size="2" face="Verdana, Arial, Helvetica, sans-serif"><strong>Price p/p</strong></font></th>	
	<th width="50" align="center"><font color="#FFFFFF" size="2" face="Verdana, Arial, Helvetica, sans-serif"><strong>Cost e/a/p/p</strong></font></th>	
	<th width="50" align="center"><font color="#FFFFFF" size="2" face="Verdana, Arial, Helvetica, sans-serif"><strong>Price e/a/p/p</strong></font></th>	
	<th width="50" align="center"><font color="#FFFFFF" size="2" face="Verdana, Arial, Helvetica, sans-serif"><strong>Stock Qty</strong></font></th>	
	<th width="50" align="center"><font color="#FFFFFF" size="2" face="Verdana, Arial, Helvetica, sans-serif"><strong>Update Qty</strong></font></th>	
	</tr>
EOD;

$product_details = '';
while ($row = mysql_fetch_array($result)) {
$pID = $row['product_id'];
$pCode = $row['prod_code'];
$pName = $row['prod_name'];
$pDesc = $row['prod_description'];
$pQtyPP = $row['prod_qty_pp'];
$pQtyEAPP = $row['prod_qty_ea_pp'];
$pCostPP = $row['prod_cost_pp'];
$pPricePP = $row['prod_price_pp'];
$pCostEAPP = $row['prod_cost_ea_pp'];
$pPriceEAPP = $row['prod_price_ea_pp'];
$pStockQty = $row['prod_stock_qty'];

$product_details .=<<<EOD

<tr bgcolor="#CACFE3">
	<td align="center"><font color="#000066" size="2" face="Verdana, Arial, Helvetica, sans-serif">$pID</font></td>
	<td align="center"><font color="#000066" size="2" face="Verdana, Arial, Helvetica, sans-serif">$pCode</font></td>
	<td align="center"><font color="#000066" size="2" face="Verdana, Arial, Helvetica, sans-serif">$pName</font></td>
	<td align="center"><font color="#000066" size="2" face="Verdana, Arial, Helvetica, sans-serif">£$pDesc</font></td>
	<td align="center"><font color="#000066" size="2" face="Verdana, Arial, Helvetica, sans-serif">£$pQtyPP</font></td>
	<td align="center"><font color="#000066" size="2" face="Verdana, Arial, Helvetica, sans-serif">$pQtyEAPP</font></td>
	<td align="center"><font color="#000066" size="2" face="Verdana, Arial, Helvetica, sans-serif">$pCostPP</font></td>
	<td align="center"><font color="#000066" size="2" face="Verdana, Arial, Helvetica, sans-serif">$pPricePP</font></td>
	<td align="center"><font color="#000066" size="2" face="Verdana, Arial, Helvetica, sans-serif">$pCostEAPP</font></td>
	<td align="center"><font color="#000066" size="2" face="Verdana, Arial, Helvetica, sans-serif">$pPriceEAPP</font></td>
	<td align="center"><font color="#000066" size="2" face="Verdana, Arial, Helvetica, sans-serif">$pStockQty</font></td>
</tr>
EOD;
}
What i would like to be able to do is use a text field for each record in the html table where the user can enter a qty and then this qty will be updated to the relevant mysql table.


feyd | Please use

Code: Select all

and

Code: Select all

tags where appropriate when posting code. Read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url][/color]
Post Reply