简体   繁体   中英

how to put an input box next to each item in a database using php

I am currently learning PHP and HTML so please bear with me.

I have a web page that shows a table, the content of this table is from a database on the localhost which constantly gets updated (this displays our stock on hand in our warehouse). The table has 3 columns - Item Number - Description - Quantity Available.

What I am trying to do is get input boxes next to each item so that the user can type in a quantity they would like to order.

I'm having trouble with seeing how I can do this. My understanding is along the lines of -> 'for each item in this item number field, create an input box' but I found that I can't run a query for the list of items and create a form\\input box at the same time (if this makes sense). So I am back to square one where all I have is a list of item numbers and no idea where to go next.

(Note: In the past there has been confusion about how they user is going to pay for the order - there is no payment facilities being implemented in this - this is just about creating input boxes for a dynamically changing database.)

Thank you, Matt

As requested - current code (apologies if I pasted it in wrong):

<?php
echo "<div id=header>";
echo "<h1>Stock on hand listing</h1>";
echo "<p>Stock is updated every hour during business hours</p>";
echo "</div>";
echo "<br />";
echo "<link rel='stylesheet' href='table.css' type='text/css'>";

$conn = mysql_connect('localhost', '*****', '*****');
if (!$conn) {
die('Could not connect: ' . mysql_error());
}
mysql_select_db('****_SOH',$conn);
/*  select only items with stock on hand */
$result = mysql_query("SELECT * FROM TABLE_SOH where (((TABLE_SOH.ITM_ONHAND)     >0))",$conn);

echo "<table border='0'>
<tr>
<th>Item</th>
<th>Description</th>
<th>On Hand</th>
</tr>";

while($row = mysql_fetch_array($result))
{
echo "<tr>";
echo "<td>" . $row['ITM_NO'] . "</td>";
echo "<td>" . $row['ITM_DES'] . "</td>";
echo "<td align=right>" . $row['ITM_ONHAND'] . "</td>";
echo "</tr>";
}
echo "</table>";

mysql_close($conn);

?>

Assuming that you have already made a sql query to get the columns -item and description , you need to insert a php code in the sql query block like

<?php

  echo ("<input type ='text' name ='item'.$i >");

?>

That should append a text column in every row of the table. $i corresponds to each item and will help you retrieve data stored in each row.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM