473,395 Members | 1,437 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

How to use checkbox to select items retrieved from a query?

I have a database of skills for our employees. I have created a form, based on a query, that displays a users skills which have the "achieved" field set to Null (which indicates that they have not achieved the desired skill). The form displays the SkillID number, the skill description, and a checkbox for the user to click. When they click the Update button, it would set the field "achieved" to "Yes" for each SkillID that the user selects.

My problem is, I do not know how to set the value of the checkbox to be whatever the SkillID is. I can make a checkbox form using a set value, but because the values are being retrieved from a query, they cannot be hard coded into the query/form. Can anyone help with this? I am totally lost. The skills needing to be updates all display accurately, now I just have to make it so users can do something with them!

Here is some code that may help. This is the code for the form. I know I need more, to process the form input, but here is where I get stuck, as I don't know how to process the input.
Expand|Select|Wrap|Line Numbers
  1. <?php
  2. session_start();
  3. $fname = $_SESSION['fname'];
  4. $lname = $_SESSION['lname'];
  5. $username = $_SESSION['username'];
  6. $user_skillID = $_POST['user_skillID'];
  7. $ud_userskillID = serialize($_POST['ud_userskillID']);
  8. $tngdate = date("d-M-y");
  9. require 'Includes/Header.php';
  10. require_once('Connections/skillsdb.php');
  11. ?>
  12. <html>
  13. <head>
  14. <title>Microsoft Access 2007 Skills Listing</title>
  15. <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
  16. <link href="Includes/si.css" rel="stylesheet" type="text/css" />
  17. </head>
  18.  
  19. <body topmargin="5" leftmargin="0">
  20. <table width="980" align="center" cellpadding = "0">
  21. <td>
  22. <tr>
  23. <th align="center">
  24.    <b>Microsoft Access 2007 skills for 
  25. <?php
  26. echo $_SESSION['fname'];
  27. echo '&nbsp;';
  28. echo $_SESSION['lname'];
  29. echo ":";
  30. ?> 
  31. <br/><p>(If no skills appear, there are no skills for you to update.)</p>
  32. </th>
  33. </tr>
  34. </td>
  35. <tr>
  36. <td>
  37. <?php require 'Includes/topicsmenu.php'; ?><br />
  38. </tr>
  39. </td>
  40. </table ><br />
  41.  
  42. <table width="800" align="center" border="1">
  43. <td>
  44. <tr>
  45.         <th>Skill ID</th>
  46.         <th>Skill Description</th>
  47.         <th>Select Achieved Skill(s)</th>
  48.  
  49. </tr>
  50. </td>
  51.  
  52. <?php
  53. mysql_select_db($database_skills, $skills);
  54.  
  55. $query_MySkills = "SELECT user_skills.user_skillID, skills.topic, skills.skill, user_skills.tngdate, user_skills.achieved, users.username, DATE_FORMAT(`tngdate`,'%d-%b-%y') AS tngdate
  56.                FROM skills, users, user_skills
  57.                WHERE users.username = ('$username') AND users.userID=user_skills.userID AND user_skills.achieved != 'N/A' AND user_skills.achieved !='Yes'
  58.         AND user_skills.skillID=skills.skillID
  59.         AND skills.topic = 'Access'
  60.                ORDER BY topic, skill";
  61.  
  62. $MySkills = mysql_query($query_MySkills, $skills) or die(mysql_error());
  63. //$row_MySkills = mysql_fetch_assoc($MySkills);
  64. $totalRows_MySkills = mysql_num_rows($MySkills);
  65.  
  66. $result = mysql_query($query_MySkills, $skills);
  67.  
  68. while($row_MySkills = mysql_fetch_assoc($MySkills))
  69.         {
  70.         echo '<tr>';
  71.         echo '<td align="center">' . ($row_MySkills['user_skillID']).'</td>';
  72.         echo '<td align="left">&nbsp;&nbsp;' . ($row_MySkills['skill']). '</td>';
  73.         echo '<td <form method="POST" action="changeskillsrecord.php">
  74. <p align="center"><input type="checkbox" name="user_skillID[]" value="$ud_userskillID">';    
  75.  
  76.         echo '</tr>';
  77.         }
  78. ?>
  79. <br /><br />
  80. <td>
  81. <td>
  82. <td>
  83. <p align="center"><input type="submit" value="Update"></p>
  84. </form>
  85. </td>
  86. </td>
  87. </td>
  88. </table>
  89. </body>
  90. </html>
  91.  
  92.  
Nov 3 '10 #1
3 2670
dlite922
1,584 Expert 1GB
shouldn't user_skillID[] be filled in with the id of that skill? so you know what to update later? You're storing a serialized $_POST var in it. You have not given me any clue as to what's in "ud_userskillID" and where it comes from.

checkmarks are not any different than any other input forms like text or select when it comes to processing it. They all have a name and values. The name should be something you could identify with PHP to do something with the value.



I'd like to point out a few other things:

1. You should do your processing (queries) before you even output the HTML. Take the results into a variable and just echo it. There's no point in having PHP echo all that HTML string that it doesn't do much with.

2. Your HTML does not validate. You're using <tr> inside a <td>. It should be the opposite. <td> should be inside a <tr> Run your html output through the w3c.org's validator. It will prevent some headaches later and will probably solve problems you didn't think you had (or make them apparent!).

3.
Nov 3 '10 #2
Ah, you're right about the "serialize". I've been trying so many different things, I've got junk in there that doesn't need to be. I removed it.

Your question "shouldn't user_skillID[] be filled in with the id of that skill? so you know what to update later?" - YES! How do I do that? The query outputs to the screen so that the user can see what skills are available (i.e. not achieved) for them to learn and check off when they learn them. I was able to create a form where the user actually typed in the skillID number one at a time and it did work, but my boss said "that's not user friendly", and wants checkboxes.

They all have a name and values. The name should be something you could identify with PHP to do something with the value.

The value needs to be the user_skillID of the skill that the user checks, but then it needs to update the field "achieved" to "Yes" when submitted. When I click a checkbox and then do "echo $user_skillID", the output is "Array", not the actual record(s) selected.
Nov 3 '10 #3
Here's a better description of what I'm trying to do:
"Many times we have to display a list of names or records for consideration and out of which user can select any number of records for further action. Here we may not know exactly how many records will be displayed as some time based on different conditions records will be collected from a table. So we can list the records with a checkbox by the side of it and user can select any number of records. We will have one unique id associated with each record and that will be used as value of the check box. The "one unique id associated with each record" already exists, so I don't need to have php count them for me to give them a unique number. I just don't know how to get that existing unique identifier number (user_skillID) to be associated with its checkbox. Does that make any more sense? Thank you.
Nov 3 '10 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

2
by: Dave Wijay | last post by:
Hi Does anybody know how to programmatically select items (rows) of a ListView in C#.NET Thanks in advanc Dave
1
by: Stephen | last post by:
Im very new to coding and I was wondering if anyone could please tell me how to select all the items in a listbox when a checkbox is checked, and then when the checkbox is unchecked to unselected...
1
by: mike robinson | last post by:
here's my code: <script type="text/javascript"> function checkUncheckAll(t, type) { for(i=1; i<t.length; i++) { if (t.name == "hosting" && type == "hosting") t.checked=t.checked; if (t.name...
2
by: Alex Simic | last post by:
Dear all I am very desperate with my problem and you might be probably my last chances for this issue. I have a listbox which is binded to a DataTable. I would like in the program to select...
6
by: Bill Nguyen | last post by:
I need to add a checkbox in front of all the rows in a datagrid so that users can select/unselect them. Any help is greatly appreciated! Bill
16
lee123
by: lee123 | last post by:
is there a way to have a product form (that has items you can choose from) and a Orderdetail form to add the items to with a button to select these items and when selected add to the orderdetail...
27
kcdoell
by: kcdoell | last post by:
Hello: I am a newbie with Java coding... I have a form that I created in Word. Within that form it had a place where the user could selected certain states or all states via a checkbox. I used...
3
by: MikeB | last post by:
I'm trying to do something and I'm sure there is a good technique for it, but I just can't figure it out. I have some member records in a database. I want to display a list of them, and have a...
1
by: kaavitha | last post by:
I am using checkbox list in my project, if the user checks multiple items how it will be updated in ms access. item1 item2 item3 item4 item5 item6 if it is checked like this, the...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.