Adding an Edit Record Radio Button for displayed results

Hi everyone. Guys im working on a page called:  showtasks_select_v4.php

It currently does the following:
- Has a select box that gets its data from a mysql table
- Has a table that displays results according to what has been selected from the select box.

What id like to add is the following...
- An Edit radio button column for the tabled results
- Upon selecting a record in the displayed table results, and clicking an "Edit this record" button,
that record is displayed in another table on the same page as the results, and is available to be edited and saved back to the database.

I have attached a printscreen of before and afters for you guys to see, plus all code for this little project.
There is only 1 php file for this...which is:  showtasks_select_v4.php
And 2 tables for mysql....       projects_pro            currenttasks_ctk

Any help greatly appreciated.
=========================================== showtasks_select_v4.php
<head>
<link rel="stylesheet" media="all" type="text/css" href="tasks.css" />
<script src="sorttable.js" type="text/javascript"></script>
 
<?php
include ("connectiondb.php");
$tbl_tasks="currenttasks_ctk";
$tbl_projects="projects_pro";
// The below filters correctly.
// $sql="SELECT * FROM `$tbl_tasks`, `$tbl_projects` where fk_id_pro_ctk = id_pro and name_pro ='mcaffee_antivirus'";   
// $sql="SELECT * FROM `$tbl_tasks`, `$tbl_projects` where fk_id_pro_ctk = id_pro and name_pro = ";   
$grabid = $_POST[projectid];
$sql="SELECT * FROM `$tbl_tasks`, `$tbl_projects` where fk_id_pro_ctk = id_pro AND id_pro = '$grabid'";
 
// $sql2="SELECT DISTINCT name_pro FROM `$tbl_tasks`, `$tbl_projects` where fk_id_pro_ctk = id_pro";
$sql2="SELECT id_pro,name_pro FROM `$tbl_tasks`, `$tbl_projects` where fk_id_pro_ctk = id_pro GROUP BY name_pro";
 
$result=mysql_query($sql);
$result2=mysql_query($sql2);
 // $res = SELECT * FROM table WHERE `location` = '".$_GET['form_location']."';  
?>
 
</head>
 
<body>
	
<form name="formcombo" method="post" action="<?php echo $_SERVER['PHP_SELF']; ?>">
           <label for="project" class="formlabels" style="margin-top:2%;">Project:</label>                        
<select name="projectid" id="projectid">
                 
                 <?php 
                        while($row2=mysql_fetch_array($result2)) {
                            if ($_POST[projectid] == $row2['id_pro'])
                                 $sel = "selected";
                            else
                                 $sel = "";
                             echo "<option value=\"".$row2['id_pro']."\" $sel>".$row2['name_pro']."\n";      
                       }
                 ?>
           </select>
 
<input type="submit" name="Submit" value="Show Tasks Belonging to this Project"><br>
</form>            
          
     
<?php
// print_r($_POST);
// echo $_POST['projectid'];
$grab = $_POST['projectid'];
// echo $grab;
?>
 
 
 
<div id="tablewrap">
	<table class="sortable" style="width:700px;">
 
		<thead>
		<tr>
			<td><b>ID</b></td>
			<td><b>Task Name</b></td>
			<td><b>Project</b></td>
			<td><b>Description</b></td>
		</tr>		
	</thead>
	<tbody>	
		<?php while($rows=mysql_fetch_array($result)){ ?>
		<tr>
			<td><?php echo $rows['id_ctk']; ?></td>
			<td><?php echo $rows['name_ctk']; ?></td>
			<td><?php echo $rows['name_pro']; ?></td>
			<td style="width:400px;"><?php echo $rows['description_ctk']; ?></td>
		</tr> <?php } ?>		
	</tbody>
	<tfoot>
	</tfoot>
	</table>
</div>
 
</body>
 
 
================================================  currenttasks_ctk:
create table currenttasks_ctk (
id_ctk int(4) not null auto_increment,
name_ctk varchar(65) not null,
fk_id_pro_ctk int(4) not null,
description_ctk text,
foreign key (fk_id_pro_ctk) references projects_pro (id_pro),
primary key (id_ctk, fk_id_pro_ctk),
unique (name_ctk)
)
engine=innodb;
 
============================================ projects_pro:
create table projects_pro (
id_pro int(4) not null auto_increment,
name_pro varchar(65) not null,
primary key (id_pro),
unique (name_pro)
)
engine=innodb;

Open in new window

ee-edit.jpg
LVL 1
Simon336697Asked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

EMB01Commented:
You should be able to add a column to the left of your ID column for your radio buttons. In the value field of the buttons should be the ID of the $row. Beneath the result set, you can add a form and simply alter the ID based upon the variable of the radio button. Let me know if you need any more help doing this.
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Simon336697Author Commented:
Hi EMB01,
Thanks for that...will try now ...... sorry for the delay :>)
0
EMB01Commented:
No worries, let me know if you need any help.
0
Cloud Class® Course: Microsoft Exchange Server

The MCTS: Microsoft Exchange Server 2010 certification validates your skills in supporting the maintenance and administration of the Exchange servers in an enterprise environment. Learn everything you need to know with this course.

Simon336697Author Commented:
Hi EMB01..... I have added the Edit Radio button....to the right, and added the ID of the $row to it.
What im not sure now is how i display the selected record.

I now have 3 forms on the page.

1) For the select box
2) For the Edit button (which I have placed in the header row section of the table)
3) For the radio buttons in the table itself


For the 3rd one, I dont have a submit input element.

Here is the code for the 3rd one...

<form name="formedit" method="post" action="<?php echo $_SERVER['PHP_SELF']; ?>">
<input type="radio" name="editme" value="<?php echo $rows['id_ctk']; ?>">            
</form>

Im trying to retrieve the value for the radio button selected with the following, which i cant get.

$grabradiotask = $_POST['editme'];

My complete code so far is in the snippet...
============================================ showtasks_select_v4.php
<head>
<link rel="stylesheet" media="all" type="text/css" href="tasks.css" />
<script src="sorttable.js" type="text/javascript"></script>
 
<?php
include ("connectiondb.php");
$tbl_tasks="currenttasks_ctk";
$tbl_projects="projects_pro";
// The below filters correctly.
// $sql="SELECT * FROM `$tbl_tasks`, `$tbl_projects` where fk_id_pro_ctk = id_pro and name_pro ='mcaffee_antivirus'";   
// $sql="SELECT * FROM `$tbl_tasks`, `$tbl_projects` where fk_id_pro_ctk = id_pro and name_pro = ";   
$grabid = $_POST[projectid];
$sql="SELECT * FROM `$tbl_tasks`, `$tbl_projects` where fk_id_pro_ctk = id_pro AND id_pro = '$grabid'";
 
// $sql2="SELECT DISTINCT name_pro FROM `$tbl_tasks`, `$tbl_projects` where fk_id_pro_ctk = id_pro";
$sql2="SELECT id_pro,name_pro FROM `$tbl_tasks`, `$tbl_projects` where fk_id_pro_ctk = id_pro GROUP BY name_pro";
 
$result=mysql_query($sql);
$result2=mysql_query($sql2);
 // $res = SELECT * FROM table WHERE `location` = '".$_GET['form_location']."';  
 
 
$grabradiotask = $_POST['editme'];
 
 echo "grabradiotask is: " . $grabradiotask;
 
?>
 
</head>
 
<body>
 
 
<!-- .................................................. wrap_formcombo_tablewrap............... -->	
	<div id="wrap_formcombo_tablewrap" style="position:absolute; left:5%;top:3%;float:left;">
 
<!-- ................................................................ formcombo ............... -->	
<form name="formcombo" method="post" action="<?php echo $_SERVER['PHP_SELF']; ?>">
           <label for="project" class="formlabels" style="margin-top:2%;">Project:</label>                        
<select name="projectid" id="projectid">
                 
                 <?php 
                        while($row2=mysql_fetch_array($result2)) {
                            if ($_POST[projectid] == $row2['id_pro'])
                                 $sel = "selected";
                            else
                                 $sel = "";
                             echo "<option value=\"".$row2['id_pro']."\" $sel>".$row2['name_pro']."\n";      
                       }
                 ?>
           </select>
 
<input type="submit" name="Submit" value="Show Tasks for Project"><br>
</form>            
          
     
<?php
print_r($_POST);
// echo $_POST['projectid'];
$grab = $_POST['projectid'];
// echo $grab;
?>
 
 
<!-- ............................................................ results table ............... -->
<div id="tablewrap">
	<table class="sortable" style="width:700px;">
 
		<thead>
			<tr>
				<td><b>ID</b></td>
				<td><b>Task Name</b></td>
				<td><b>Project</b></td>
				<td><b>Description</b></td>
				<td>
					<form name="formeditrecord" method="post" action="<?php echo $_SERVER['PHP_SELF']; ?>">
						<input type="submit" name="Submit" value="Edit">			
					</form>
				</td>
			</tr>		
			</thead>
	<tbody>	
		<?php while($rows=mysql_fetch_array($result)){ ?>
		<tr>
			<td><?php echo $rows['id_ctk']; ?></td>
			<td><?php echo $rows['name_ctk']; ?></td>
			<td><?php echo $rows['name_pro']; ?></td>
			<td style="width:400px;"><?php echo $rows['description_ctk']; ?></td>
			<td>
				<form name="formedit" method="post" action="<?php echo $_SERVER['PHP_SELF']; ?>">
					<input type="radio" name="editme" value="<?php echo $rows['id_ctk']; ?>">				
				</form>
			</td>			
		</tr> <?php } ?>		
	</tbody>
	<tfoot>
	</tfoot>
	</table>
</div> <!-- end of tablewrap div -->
<!-- .............................................................. results table ............... -->
 
</div> <!-- end of wrap_formcombo_tablewrap div-->
 
 
 
</body>

Open in new window

0
Simon336697Author Commented:
Hi EMB01,
Bud here is a quick screen dump of what it currently looks like...
All works except that I cannot display the selected record with the Edit button .
ee-q.jpg
0
Simon336697Author Commented:
EM,
Another screenshot mate :>)
ee-q2.jpg
0
Simon336697Author Commented:
When adding an input for submit, i get a value for grabradiotask, but check the screen dump mate :>)
ee-q3.jpg
0
Simon336697Author Commented:
EM,
Mate do you want me to close this question and open another one bud?
0
EMB01Commented:
No you don't have to open up a new one. I can try to get the radio button method to work if you want. But it would be basically the same and a lot easier to just make the radio buttons submit buttons, then on submit register the $row_['ID'] to the form (below) on that same page. What do you want to do?
0
EMB01Commented:
If you want to do it in two steps, as you have it, just make a form on that page and make your SQL UPDATE query use the value of $grabradiotask. I recommend that you use just one step, replace the radio button with a submit button and capture the value that way. Then, use the same method for updating the SQL. Let me know which way you want to go and if you need any help.
0
EMB01Commented:
If you want to use radio buttons, all you need to do is this:
Change your radio button HTML to <input type="radio" name="radio" value="$row['ID']">

Then, add this PHP code in your <head>:
<?php
if(isset($radio))
{
  $id = $radio;
} else {
  $id = 0;
}
?>

Finally, make the form below update using the ID of $radio. If you are using a processing script on another page, your update form would look like this:
<form name="myform" action="/processing_script.php?<?php echo $id; ?>" method="POST">

Just let me know what you are trying to do. If you want to open a new question for this, let me know where it is so I can help!
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
PHP

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.