Link to home
Start Free TrialLog in
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?

User generated image
SOLUTION
Avatar of SStory
SStory
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of LB1234
LB1234

ASKER

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>
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&
Avatar of LB1234

ASKER

Ah, thanks COBOL!

Can you please shed some light on the PHP code  and SQL statement I'd use?
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
ASKER CERTIFIED SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of LB1234

ASKER

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
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial