Radio buttons in a table

All,

I am displaying information from a MySQL database in table form. One of the columns will contain two radio buttons for “Reviewed” and “Resolved.” The user will select (or not) one of the two options for one or more rows. On form submission, I will need to update the database accordingly.

I have successfully placed the radio buttons, but cannot get them to work correctly. If I give the options the same name with the record ID then the table works correctly, but it does not carry information over into my submission script. If I remove the record ID from the button name then the information carries over correctly, but the table does not work.

I’m new to using radio buttons with PHP, so forgive me if I’m asking a routine questions here.

Testopen.php:

[php]

<?php session_start(); if( $_SESSION['user_level']=='superadmin'){ include 'RemoveBlank.php'; ?>
<style type="text/css">
table.inet td { width: auto; }
.container { text-align: left; }
table.inet thead {
	background-color: black;
	color: white;
	text-indent: 14px;
	text-align: left;
}
table.inet tbody tr:nth-child(odd) { background-color: rgba(51, 204, 255, 0.6); }
table.inet tbody tr:nth-child(even) { background-color: rgba(51, 255, 102, 0.3); }
table.bridge td { width: auto; } .container { text-align: left; } table.bridge thead { background-color: black; color: white; text-indent: 14px; text-align: left; } table.bridge tbody tr:nth-child(odd) { background-color: rgba(255, 204, 204, 0.6); } table.bridge tbody tr:nth-child(even) { background-color: rgba(143, 255, 255, 0.3); }

New Issues


Internet Speeds

<?php mysql_connect('localhost','root','admin'); $query=("SELECT * FROM speedtest.data WHERE issuecreated = 'New' ORDER by ID DESC"); $result=mysql_query($query); $num=mysql_numrows($result); $i=0; while ($i < $num) {

$ComputerName=mysql_result($result,$i,“ComputerName”);
$ExpectedRig=mysql_result($result,$i,“ExpectedRig”);
$Timestamp=mysql_result($result,$i,“Timestamp”);
$download=mysql_result($result,$i,“download”);
$upload=mysql_result($result,$i,“upload”);
$latency=mysql_result($result,$i,“latency”);
$jitter=mysql_result($result,$i,“jitter”);
$testServer=mysql_result($result,$i,“testServer”);
$ip_address=mysql_result($result,$i,“ip_address”);
$hostname=mysql_result($result,$i,“hostname”);
$issuecreated=mysql_result($result,$i,“issuecreated”);
$id=mysql_result($result,$i,“ID”);

?>

<?php $i++;}// end while echo "
computerName ExpectedRig timestamp download upload latency jitter testServer ip_address hostname Issue Created Update Status
<?php echo $ComputerName; ?> <?php echo $ExpectedRig; ?> <?php echo $Timestamp; ?> <?php echo $download; ?> <?php echo $upload; ?> <?php echo $latency; ?> <?php echo $jitter; ?> <?php echo $testServer; ?> <?php echo $ip_address; ?> <?php echo $hostname; ?> <?php echo $issuecreated; ?> Reviewed Resolved
      </label></td>
"; ?>

Bridges

<?php // database connection info mysql_connect('localhost','***','***'); $query=("SELECT * FROM speedtest.bridges WHERE issuecreated = 'New' ORDER by ReportID DESC"); $result=mysql_query($query); $num=mysql_numrows($result); $i=0; ?> <?php while ($i < $num) { $ComputerName=mysql_result($result,$i,"ComputerName"); $ExpectedRig=mysql_result($result,$i,"ExpectedRig"); $Timestamp=mysql_result($result,$i,"Timestamp"); $MAC=mysql_result($result,$i,"MAC"); $Signal=mysql_result($result,$i,"onlysignal"); $TxRxMbps=mysql_result($result,$i,"TxRxMbps"); $CCQ=mysql_result($result,$i,"CCQ"); $ConnectionTime=mysql_result($result,$i,"ConnectionTime"); $LastIP=mysql_result($result,$i,"LastIP"); $issuecreated=mysql_result($result,$i,"issuecreated"); $id=mysql_result($result,$i,"ReportID"); ?> <?php echo ""; $i++;} // end while echo "
computerName ExpectedRig timestamp MAC Signal TxRxMbps CCQ ConnectionTime Last IP Issue Created Actions
<?php echo $ComputerName; ?> <?php echo $ExpectedRig; ?> <?php echo $Timestamp; ?> <?php echo $MAC; ?> <?php echo $Signal; ?> <?php echo $TxRxMbps; ?> <?php echo $CCQ; ?> <?php echo $ConnectionTime; ?> <?php echo $LastIP; ?> <?php echo $issuecreated; ?>
"; } ?>

 

 

[/php]

For the time being, I have a simple script on my submission page, just so I can see the data before I do anything with it.

[php]mass review test

<?php if(count($_POST) > 0){ $update = $_POST['update']; echo $update; } ?>
What did I say about clicking these buttons?[/php]

LOL, I had that same problem a few years ago when I used my first radio button in a PHP project.

So, to explain how I solved it. I did use the same name for the buttons. I used different values for each.
In the saving code, since only one of the buttons may be checked, I just saved the current value in the
database field. Worked great.

But, how to redisplay it. That was tricky until I learn the way to fix it. On the display end, when a radio
button is displayed, it has a checked option in it. "checked=“checked” works. So, after each radio is put
out, you have to add a test to see if that is the value in the database. Then, if it is, you check it.

Something like:
<input type=“radio” <?PHP if ($thisitemfromDB=="reviewed") echo "checked='checked' ";?> >;

Note: you have to place this test inside of the INPUT field and watch out for quotes and double quotes.

Hope that helps…

Oh, one other comment on your code…

You can use multiple forms on one page, but, it is not needed.

Since the output of each of your forms go to a PHP file, you can just use one file to call.
Use one with multiple buttons inside it. Send it to just one page. In that one page,
you check for which button is pressed by using their names. ( If isset($_POST[“button1”]) then… )
So, then, you do a routine for each of the button and if needed redirect inside the PHP code instead
of the HTML code.

Why do it this way? Security is better. People can right-click on your page and see the names of your
pages you are calling in the form line. This cuts down the number of files they can locate. ( PHP hides
from browsers and is SERVER-SIDE only. ) Also, less pages to deal with. And, most importantly, the
less code you use and the less pages used means your site loads faster.

Hope that makes sense and helps…

Sponsor our Newsletter | Privacy Policy | Terms of Service