Jump to content

Updating multiple records in MYSQL using PHP


bmopro

Recommended Posts

Hello,
I may be over simplifying this, but i want to try and keep this as simple as possible...
I am trying to write my own script to edit multiple records in a table without having to use phpmyadmin as a front end.  THe reason...So i can view just one field and edit another with a drop down menu and not have to view all of the fields in the table.
The way i have it set up now is, i query the DB and use a for loop to echo out a table with the name field and a drop down men to edit another field for each entry. 
To test  this code i kept it simple and just put 1 entery in the db.  So, when i query the db it only shows 1 entery.
When i try and just have it echo out the name field when it hit submit, i get nothing?  When you use a for loop to echo out multple records does the html form see it differently?  Is there a third party code i can use to do this?
Sorry in advance if this is to vague, but if someone could point me in the right direction to help understand this concept, i am grateful.
Brian
Link to comment
Share on other sites

It's really hard to help without seeing any code, but I think what your trying to do is something like this:

[code]
<?php

$item = $_POST["item"];
?>
<form action="yoursite.php" method="post">
<select>
<option value="Item_1">Item 1</option>
<option value="Item_2">Item 2</option>
<option value="Item_3">Item 3</option>
</select>
</form>

<?php
$sql = mysql_query("SELECT * FROM `your_table` WHERE `item_id` = '$item'") or die(mysql_error());
while ($row = mysql_fetch_array($sql))
{
         // You're tables information here, just do the following for each field name:
         echo $row["field_name"];
}

?>
[/code]
Link to comment
Share on other sites

I got it, but thats what i already do.
For each row of data i have the for loop eco out a table with three cells.
The first is a check box, with the value of true.  THe second is a text box like you have below.
the third is a drop down menu so i can edit that field.
Now when i retrieve the data, in the testing im doing, i only have 1 row of data.
When i hit my submit button, it queries the db and echos out that row of data in the format above.
I want it to be able to update that row of data if i check the check box, and not to if the check box is unchecked.  I've been testing this out, and so far when i hit the submit button to update, all i have it doing is echo out the name text box which it dosn't do.  I don't have a problem doing it one entery at a time, which ive been doing, but if there are multiple rows of data echoed out by a for loop, will it still work the same as if i were doing it one at a time. (Obviously i have to set up another loop to update only the checked boxes, and assign unique names th all of the text boxes ect which will be the id # of the entery.
example: name_101)
Thanks for the help, and i hope this makes scence.
Brian
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.