Solved

Adding an Edit Record Radio Button for displayed results

Posted on 2008-09-29
11
848 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
  • 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
 
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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Deprecated and Headed for the Dustbin By now, you have probably heard that some PHP features, while convenient, can also cause PHP security problems.  This article discusses one of those, called register_globals.  It is a thing you do not want.  …
Build an array called $myWeek which will hold the array elements Today, Yesterday and then builds up the rest of the week by the name of the day going back 1 week.   (CODE) (CODE) Then you just need to pass your date to the function. If i…
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.
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 …

895 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

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now