473,605 Members | 2,727 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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

6 New Member
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 2688
dlite922
1,584 Recognized Expert Top Contributor
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
Joni Seth
6 New Member
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
Joni Seth
6 New Member
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
16285
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
1799
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 the items in the listbox. Here is the event I would like to put this into. private void chkSelectAll_CheckedChanged(object sender, System.EventArgs e) { }
1
2862
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 == "se" && type == "se") t.checked=t.checked; if (t.name == "ml" && type == "ml") t.checked=t.checked; }
2
2215
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 in this listbox some items. I try to do this with following (of course much more profesional - but let's keep it simple):
6
1709
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
2243
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 form. anotherwords, if you have a product form with items in it you could highlight the items then click a save or select button and add the items you have selected in an orderdetail subform. because right now i am using a combo box with the items in it...
27
5865
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 VBA coding to do this and it works great. My problem is now I have to convert the form to an Adobe 8.0 pdf form. The conversion process does not bring over the VBA logic. So I placed the check boxes for each state and then inserted an object...
3
1396
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 checkbox next to each member. One can then click in the checkboxes for one or more members and the next page should then take action on the selected members. I know how to get the members from the database, I know how to create the form to...
1
2173
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 checked items should be updated how can i do this
0
8001
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
7934
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8415
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8069
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
6742
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
5886
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
3912
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
3958
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1270
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.