Solved

Adding an Edit Record Radio Button for displayed results

Posted on 2008-09-29
11
856 Views
Last Modified: 2012-08-13
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
0
Comment
Question by:Simon336697
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 6
  • 5
11 Comments
 
LVL 14

Accepted Solution

by:
EMB01 earned 500 total points
ID: 22599650
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
 
LVL 1

Author Comment

by:Simon336697
ID: 22601776
Hi EMB01,
Thanks for that...will try now ...... sorry for the delay :>)
0
 
LVL 14

Expert Comment

by:EMB01
ID: 22601887
No worries, let me know if you need any help.
0
MS Dynamics Made Instantly Simpler

Make Your Microsoft Dynamics Investment Count  & Drastically Decrease Training Time by Providing Intuitive Step-By-Step WalkThru Tutorials.

 
LVL 1

Author Comment

by:Simon336697
ID: 22602095
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
 
LVL 1

Author Comment

by:Simon336697
ID: 22602118
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
 
LVL 1

Author Comment

by:Simon336697
ID: 22602174
EM,
Another screenshot mate :>)
ee-q2.jpg
0
 
LVL 1

Author Comment

by:Simon336697
ID: 22602187
When adding an input for submit, i get a value for grabradiotask, but check the screen dump mate :>)
ee-q3.jpg
0
 
LVL 1

Author Comment

by:Simon336697
ID: 22602200
EM,
Mate do you want me to close this question and open another one bud?
0
 
LVL 14

Expert Comment

by:EMB01
ID: 22605697
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
 
LVL 14

Expert Comment

by:EMB01
ID: 22607338
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
 
LVL 14

Expert Comment

by:EMB01
ID: 22616376
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

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Foreword (July, 2015) Since I first wrote this article, years ago, a great many more people have begun using the internet.  They are coming online from every part of the globe, learning, reading, shopping and spending money at an ever-increasing ra…
Developers of all skill levels should learn to use current best practices when developing websites. However many developers, new and old, fall into the trap of using deprecated features because this is what so many tutorials and books tell them to u…
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

623 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question