html table and php

Javascript coding ..

Moderators: macek, egami, gesf

New php-forum User
New php-forum User
Posts: 1
Joined: Thu Nov 22, 2012 3:54 pm

html table and php

Postby gigi82 » Thu Nov 22, 2012 4:12 pm

Hi to all.

I'm quite new in php.

I have an HTML table with two button for each row. When I press one of these buttons in a specific row, I want to edit the row correspondent and take all the values related to that row.

This is the code:

Code: Select all




<form id="view_admin" method="post">

<table id="my_table" class= "sample" >

<td align="center"><strong><font face="Arial, Helvetica, sans-serif">Id</font></strong></td>
<td align="center"><strong><font face="Arial, Helvetica, sans-serif">Column1</font></strong></td>
<td align="center"><strong><font face="Arial, Helvetica, sans-serif">Status</font></td>
<td align="center"><strong><font face="Arial, Helvetica, sans-serif">Edit Status</font></td>


while ($i < $num) {



<td align="center"><font face="Arial, Helvetica, sans-serif"><?php echo $f0; ?></font></td>
<td align="center"><font face="Arial, Helvetica, sans-serif"><?php echo $f1; ?></font></td>
<td align="center"><font face="Arial, Helvetica, sans-serif"><?php echo $f2; ?></font></td>
<td align="center"><input type="submit" name="approved" value="approve"> <input type="submit" name="refused" value="refuse"> </td>

if (isset($_POST['approved'])) {
$query_update = "UPDATE main SET status='APPROVED' WHERE id ='$f0'";
else if (isset($_POST['refused'])) {
$query_update = "UPDATE main SET status='REFUSED' WHERE id ='$f0'";




If I press a button in a row, now I update all the rows and not the selected row.
I'm thinking to assign a progressive number (variable $i php)to each row and then use a javascript function to detect the selected row. How can I do this?

Thank you.

php-forum Fan User
php-forum Fan User
Posts: 858
Joined: Mon Oct 01, 2012 12:32 pm

Re: html table and php

Postby seandisanti » Tue Nov 27, 2012 11:35 am

You don't want to use javascript for that, keep all of your logic and processing server side. The following code isn't tested because i didn't want to create a table, but it should work as is.

Code: Select all

// assume connection already made
if (! isset($_POST)) { //not responding to form, must draw it
echo '<form id="view_admin" action="' $_SERVER['SCRIPT_NAME'] . '" method="post">';
'<th>Column 1</th>';
        while (
$theRow '<tr>';
$theRow .= '<td><input type="text" disabled="disabled" value="' $row['id'] . '" name="id"></td>';
$theRow .= '<td><input type="text" disabled="disabled" value="' $row['column1'] . '" name="column1"></td>';
$theRow .= '<td><input type="text" disabled="disabled" value="' $row['status'] . '" name="status"></td>';
$theRow .= '<td><input type="submit" name="reject" /><br /><input type="submit" name="approve" /></td>';
$theRow .= '</tr>';
} else { //responding to form
if (isset($_POST['approve'])){ //it's an approval
$sql "UPDATE main SET status='APPROVED' WHERE id =" $_POST['id'];
        } else {
$sql "UPDATE main SET status='REFUSED' WHERE id =" $_POST['id'];
mysql_affected_rows() . ' rows updated.';

Return to “JavaScript”

Who is online

Users browsing this forum: No registered users and 3 guests