Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

update database based upon html table 1

Status
Not open for further replies.

edpatterson

IS-IT--Management
Feb 24, 2005
186
The more I search, the more confused I get...

I would like to present a user with data laid out in a HTML table. The original data is in a MySQL database. Each row in the table contains:
[tt]
(urlID)(listName)(urlName)(urlDesc)
[/tt]
The user will only be able to change (listName) field and there could be a couple hundred rows in the table.

I am assuming I would need to make some kind of array for each row then send the arrays back via a form post then generate a huge honkin query statement to update the tables.

I can query the original data out and present it in a table, it is the converting the table cells into form elements and processing the posted data that has me confused.

As I it is I manually query out the data and make the assignments, but I am tired of being the 'url boy' (Monty Python reference).

Thanks for any assistance,
Ed
 
All you would need to do for the form elements is output the relevant html for them. so in your table if you are outputting something like:

Code:
echo "<tr><td>$row['somefield']</td>...";

just output a form element inside the html table such as:

Code:
echo "<tr><td>[red]<input type=text name=editablevalue> value=[/red]$row['somefield'][red]>[/red]</td>...";


Of course you would need to surround your table with a form element. <form action...>


You can make your editablevalue and array, and then use it in a loop to update the table.



----------------------------------
Ignorance is not necessarily Bliss, case in point:
Unknown has caused an Unknown Error on Unknown and must be shutdown to prevent damage to Unknown.
 
Thanks, could you give me an example using the output from a mysql query ($result)?

Currently I have this to build the table:[tt]
while($row = mysql_fetch_array($result)){
echo "<tr>";
echo "<td width='10%'>$row[0]</td>"; // urlID
echo "<td width='10%'>$row[1]</td>"; // listName
echo "<td width='20%'>$row[2]</td>"; // urlName
echo "<td width='60%'>$row[3]</td>"; // urlDesc
echo "</tr>";
}[/tt]
I am confused how to make each row unique for form processing and sql generation.
 
I wonder why you want to start that low level, there are many samples out there to make a table edit form.

Apply Vacunitas idea you'd change the line showing the editable listname:

Code:
echo "<td width='10%'><input type=text name=listName
> value=$row[1]></td>"; // listName

In the script taking the submitted data you'd also need to know which URLID the committed listname belongs to, therefore you'd add a hidden input with theurlID, so submitting the form would at least submit a pair or urlID and listname, which you can use in an update SQL statement.

Bye, Olaf.
 
sorry, misposted:

Code:
echo "<td width='10%'><input type=text name=listName value=$row[1]></td>"; // listName

Bye, Olaf.
 
I wonder why you want to start that low level, there are many samples out there to make a table edit form.
I am starting at the level that makes the most sense to me, I do/did not see any other place to start. The samples I have found are so convoluted that I ended up more confused then when I began. Perhaps I am making this harder that it really is.
I am working with a demo query that returns 5 records. Using your supplied sample it appears that I would only get the value of the 5th listName when the user clicked the submit button. Just the pertinent code is shown
Code:
<?php
  echo "<table>;
  echo "<form action='dispaly-results.php' method='post'>";
  while($row = mysql_fetch_array($result)){
    echo "<tr>";
    echo "<td>$row[0]</td>";  // urlID
    echo "<td><input type='text' name='list' value ='".$row[1]."'</td>"; // listName
    echo "<td>$row[2]</td>"; // urlName
    echo "<td>$row[3]</td>"; // urlDesc
    echo "</tr>";
  }
  echo "<input type='submit'>";
  echo "</form>";
  echo "</table>";
?>
-- output --
[tt]
1 Staff .211atyourfingertips.org Crisis Center Tampa Bay
2 Disaster .anywho.com number lookup
3 Personnel .apsnetwork.org National Adult Protective Services Association
4 Administration .asq.org American Society for Quality
5 MIS .avmed.com AVMED
[/tt]
-- end of display --
-- display-results.php
<?php
// display-choices.php
echo $_POST["list"];
?>
--
displays MIS which is the last listName which makes sense since it did not display Array like I thought it might. For it to return a list for each line item the post value would have to be an array. No?
This is the point where the confusion begins. I need either the rows that have been changed, or all of the rows.
 
Correct, so you need to make the textbox and array.

Add square brackets [] to the name of the text box and PHP will automagically convert it into an array. So you'll get the values for all the textboxes.

Code:
    echo "<td><input type='text' name='list[red][][/red]' value ='".$row[1]."'</td>"; // listName




----------------------------------
Ignorance is not necessarily Bliss, case in point:
Unknown has caused an Unknown Error on Unknown and must be shutdown to prevent damage to Unknown.
 
OK, almost there, I should have warned you I am rather thick.
On the table building page[tt]
echo "<td><input type='text' name='list[]' value ='".$row[1]."'</td>\n"; // listName [/tt]
page source view [tt]
<td>[red]<input type='text' name='list[]' value ='Blacklist'[/red]</td> [/tt]
I changed all 5 of the text boxes to TESTING then clicked the submit button.
-- display-choices.php -- [tt]
<html>
<head><title>display Choices</title></head>
<body>
<?php
for ($i = 0;$i<=5;$i++){
echo $_POST['list[$1]']."<br>\n";
}
?>
</body></html>[/tt]
-- display Choices page is blank, here is the source -- [tt]
<html>
<head><title>display Choices</title></head>
<body>
<br>
<br>
<br>
<br>
<br>
<br>
</body></html> [/tt]
Sigh, I have tried name='list[$row[0][]]' on the creation side, same thing. Nothing returned.





 
2 things: Your variable is a number one 1 as opposed to a letter i in your loop.

And second to address the array within a POST variale you add the array to the outside of the variable:

Code:
<?php
  for ($i = 0;$i<=5;$i++){
    echo $_POST['list'][red][$[blue]i[blue]][/red]."<br>\n";
  }

----------------------------------
Ignorance is not necessarily Bliss, case in point:
Unknown has caused an Unknown Error on Unknown and must be shutdown to prevent damage to Unknown.
 
Sorry got a problem with the TGLM color codes.


Code:
 for ($i = 0;$i<=5;$i++){
    echo $_POST['list'][red][$[blue]i[/blue]][/red]."<br>\n";
  }

----------------------------------
Ignorance is not necessarily Bliss, case in point:
Unknown has caused an Unknown Error on Unknown and must be shutdown to prevent damage to Unknown.
 
Thank you so very much for the spoon feeding! I really do appreciate it. I can now put together the editor and delegate the 'url boy' duties.

Ed
 
Glad I could help.

----------------------------------
Ignorance is not necessarily Bliss, case in point:
Unknown has caused an Unknown Error on Unknown and must be shutdown to prevent damage to Unknown.
 
I don't know if that was an error typing your code here, but you're also missing the closing tag for the input element:
Code:
echo "<td><input type='text' name='list[]' value ='".$row[1]."'[!] />[/!]</td>\n"; // listName

___________________________________________________________
[small]Do something about world cancer today: Comprehensive cancer control information at PACT[/small]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top