Jump to content


Photo

Updating multiple records in MYSQL using PHP


  • Please log in to reply
4 replies to this topic

#1 bmopro

bmopro
  • Members
  • PipPip
  • Member
  • 13 posts

Posted 04 October 2006 - 08:21 PM

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

#2 tleisher

tleisher
  • Members
  • PipPipPip
  • Advanced Member
  • 88 posts

Posted 04 October 2006 - 09:19 PM

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

<?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"];
}

?>


#3 bmopro

bmopro
  • Members
  • PipPip
  • Member
  • 13 posts

Posted 04 October 2006 - 09:46 PM

Basically yes that is the way to retreve the info from the db, but how do you update that ifno after you have echoed it out to the browser.

#4 tleisher

tleisher
  • Members
  • PipPipPip
  • Advanced Member
  • 88 posts

Posted 04 October 2006 - 09:58 PM

What exactly do you mean update it? You mean you want to be able to edit each field in the row? If thats the case just create an input type for each IE:

<input type="text" name="name" value="<?php echo $row["name"]; ?>">

etc.

#5 bmopro

bmopro
  • Members
  • PipPip
  • Member
  • 13 posts

Posted 04 October 2006 - 10:19 PM

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




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users