View Full Version : php mysql html help

09-03-2005, 01:28 PM
Greetings all
What I need to do is to pull a selection of values from a database change them and then put them back in

see here (http://nigel.geek.nz/annak/set_exchange.php) for what I am meaning (the submit button is disabled) the problem is when I am pulling them out I am using a loop

mysql_select_db($dbname, $conn);
$query_result = "SELECT * FROM store";
$result = mysql_query($query_result, $conn) or die(mysql_error());
while ($row_result = mysql_fetch_array($result)) {
echo '<tr><td width="20%">';
echo $row_result["p_name"];
echo '</td><td width="10px">';
echo $row_result['p_no'];
echo '</td><td width="15px"><strong><input type="text" name="nz_price" size="10" Value ="';
echo $row_result['nz_price'];
echo '"></td><td width="15px"><strong><input type="text" name="us_price" size="10" Value ="';
echo $row_result['us_price'];
echo '"></td><td width="15px"><strong><input type="text" name="au_price" size="10" Value ="';
echo $row_result['au_price'];
echo '"></strong></td></tr>';

as you can see all text inputs have the same names on each row, what I want to do is to make the names different for each row

row 1 us_price1 au_price1 au_price1
row 2 us_price2 au_price2 au_price2
row 3 us_price3 au_price3 au_price3
row 4 us_price4 au_price4 au_price4
row 5 us_price5 au_price5 au_price5
and so on



09-03-2005, 05:18 PM
Ok no help yet

Does anyone know of a good site/forum which specialises in php mysql etc
as last time I went to one, and asked a stupid (read newbie) question, the response i got was not overly polite, which is why I stick with pf1 normally.
No I am not abandoning PF1 but on such a site my question is liable to have been asked, answered and filed away in the archives


09-03-2005, 07:33 PM
You are calling all the records in the database.
If this is what you want to do, add an update method to each line with a WHERE condition based on a unique identifier.

As an alternative use a popup window with the data relating to the specific record to be altered. Again base the popup on a WHERE condition based on a unique identifier.

He who laughs, lasts
- Mary Pettibone Poole

09-03-2005, 08:17 PM
Theres two ways around this, the easy way, and the hard way.

The easy way is just displaying the table with 'Edit' at the end of each, that way you can selectively edit each entry with out any hassle.

The other way is using your original setup, but making the field names multidimensional arrays and looping over them on form submit.


mysql_select_db($dbname, $conn);

$query = "SELECT * FROM store";
$result = mysql_query($query, $conn) or die(mysql_error());

while ($row_result = mysql_fetch_array($result))
<td><input type="text" name="prod[<?=$row_result['p_no']?>][nz_price]" Value ="<?=$row_result['nz_price']?>"></td>
<td><input type="text" name="prod[<?=$row_result['p_no']?>][us_price]" Value ="<?=$row_result['us_price']?>"></td>
<td><input type="text" name="prod[<?=$row_result['p_no']?>][au_price]" Value ="<?=$row_result['au_price']?>"></td>


I'm not entirely sure on how to do this but maybe that might put you in the right direction?

Good luck.

09-03-2005, 11:17 PM
Thanks guys I went with arrays and got it working,

eventually i will be doing a litle edit button next to the rows but for now the client wants to update everything on his dB so clicking on edit for each entry will take a while

anyway thanks you've given me a few more things to think about