Avatar of LB1234
LB1234 asked on

Setting up unique names (for MySQL functionality) for each entry in a table pulled from a database

Please look at the attached image.  Each row in this table is being pulled from a database.  But in order to save the entered information (various notes entered, whether something has been checked "done" or not, and the entered value for the drop down list shown here) each element on each line must have a unique name for the processing page right?  So the first line, would have a form name of "note1" and "note2" -- they cannot both be called "note" correct?  Conceptually, how do I accomplish this?  A foreach statement or something?

table picture
PHPMySQL ServerHTMLCOBOL

Avatar of undefined
Last Comment
Ray Paseur

8/22/2022 - Mon
SOLUTION
SStory

Log in or sign up to see answer
Become an EE member today7-DAY FREE TRIAL
Members can start a 7-Day Free trial then enjoy unlimited access to the platform
Sign up - Free for 7 days
or
Learn why we charge membership fees
We get it - no one likes a content blocker. Take one extra minute and find out why we block content.
See how we're fighting big data
Not exactly the question you had in mind?
Sign up for an EE membership and get your own personalized solution. With an EE membership, you can ask unlimited troubleshooting, research, or opinion questions.
ask a question
SOLUTION
Julian Hansen

Log in or sign up to see answer
Become an EE member today7-DAY FREE TRIAL
Members can start a 7-Day Free trial then enjoy unlimited access to the platform
Sign up - Free for 7 days
or
Learn why we charge membership fees
We get it - no one likes a content blocker. Take one extra minute and find out why we block content.
See how we're fighting big data
Not exactly the question you had in mind?
Sign up for an EE membership and get your own personalized solution. With an EE membership, you can ask unlimited troubleshooting, research, or opinion questions.
ask a question
ASKER
LB1234

This table is actually an HTML form populated with info being pulled from an MYSQL database.  I'd like people to update the form info, hit submit and then the data for each row of the form is saved back into the database.

Here's the code for the entire thing.  

<form action="process_table.php" method="post">

<table>
  <tr>
<th scope="col">Date</th>
<th scope="col">Amount</th>
<th scope="col">Vendor</th>
<th scope="col">Description</th>
<th scope="col">Type</th>
<th scope="col">Notes</th>
<th scope="col">Trip</th>
<th scope="col">Last Updated</th>
<th scope="col">Last Updated By</th>
<th scope="col">Done</th>

 
  </tr>
 
<?php

$get_transactions = "SELECT * FROM transactions order by date ASC LIMIT 10";
$transactions_result_set = mysqli_query($connection, $get_transactions);

$get_types = "SELECT * FROM type";
$type_result_set = mysqli_query($connection, $get_types);

?>  

<?php // this section creates the entire table
//the line below creates each record and puts it in a table
?>

<?php
//this opens the tag
$type = "<select>";
//this while statement turns each entry from the database into value
while ($row = mysqli_fetch_assoc($type_result_set)) {
//this statement appends to the existing variable    
       $type .= sprintf("<option value='%s'>%s</option>", $row["type_name"], $row["type_name"]);
}
$type .= "</select>";
?>

<?php while ($expenses = mysqli_fetch_assoc($transactions_result_set)) {
?>

 <tr>
 <td><?php echo date("F d, Y", strtotime($expenses["date"]));?></td>
 <td><?php echo number_format($expenses["amount"], 2);?></td>
 <td><?php echo $expenses["vendor"];?></td>
 <td><?php echo $expenses["description"];?></td>
 <td><?php echo $type; ?></td>
 <td><textarea name="notes" id="notes"></textarea></td>
 <td nowrap="nowrap">Trip place holder</td>
 <td><?php echo date("m/d/Y")?></td>
  <td>User Name</td>
<!--  <td><?php// date("F d, Y");?></td>-->
 
 <td><input name="done" type="checkbox" id="done"></td>
 
 </tr>
 
 
<?php
}
?>

      
</table>

<input type="submit">
</form>
COBOLdinosaur

It looks like the textarea is the field you need the array for so do it this way:

<textarea name="name[]"...

Then when it is sunmited you will have an array in the $_POST variables and can reference as:

$_POST['name[0]'], $_POST['name[1]'], etc

Cd&
ASKER
LB1234

Ah, thanks COBOL!

Can you please shed some light on the PHP code  and SQL statement I'd use?
Experts Exchange is like having an extremely knowledgeable team sitting and waiting for your call. Couldn't do my job half as well as I do without it!
James Murphy
SOLUTION
Log in to continue reading
Log In
Sign up - Free for 7 days
Get an unlimited membership to EE for less than $4 a week.
Unlimited question asking, solutions, articles and more.
ASKER CERTIFIED SOLUTION
Log in to continue reading
Log In
Sign up - Free for 7 days
Get an unlimited membership to EE for less than $4 a week.
Unlimited question asking, solutions, articles and more.
SOLUTION
Log in to continue reading
Log In
Sign up - Free for 7 days
Get an unlimited membership to EE for less than $4 a week.
Unlimited question asking, solutions, articles and more.
ASKER
LB1234

The only time during any given day when I feel like a complete idiot is when I'm trying to code/learn  PHP.  I'm a network administrator learning this stuff on my own and PHP is my first language.  I should be compensated for the ongoing battery of my ego!  Guys, I will pore over the helpful code provided and try to understand it. Will get back to you soon, thanks!
SOLUTION
Log in to continue reading
Log In
Sign up - Free for 7 days
Get an unlimited membership to EE for less than $4 a week.
Unlimited question asking, solutions, articles and more.