Page 1 of 1

Question in HTML+PHP please helppppp me

Posted: Sun May 18, 2008 12:46 pm
by THE HONY
<<< my friends >>

I want to create form contains multiple checkboxes.

How i can create name for every checkbox by using php

because i want to sent the value for every checkbox to databas, therefore that must be different

Thank you for every body

<< The hony>

Re: Question in HTML+PHP please helppppp me

Posted: Sun May 18, 2008 3:14 pm
by JAB Creations
You're going to have to be a bit clearer then that. Why do you need to have PHP create the checkbox names instead of just writing them out yourself?

Re: Question in HTML+PHP please helppppp me

Posted: Sun May 18, 2008 3:28 pm
by THE HONY
<THANKS>

I explain that :
1- I have table contains students names(number of rows in the table ==number of students with me)
2- then i want to take attendance for every student.
if student present--->check checkbox
if student absent --->uncheck
3- i will send values of checkboxes to the database
therefor i need name for every checkbox


<<<Thanks again>>>

Re: Question in HTML+PHP please helppppp me

Posted: Sun May 18, 2008 5:01 pm
by califdon
We are trying to understand your question. Probably your primary language is not English, so this makes it more difficult. I know I could not explain something in your language, so I understand how difficult it may be for you.

I think you have in mind a web page with a list of student names from a table, with a checkbox next to each name, so you can indicate attendance. But how will you store this data? Usually this will require 2 tables, one for names, one for attendance for each student, each day. You cannot write a PHP program first, then figure out how to store the data. You must first plan how the data will be stored. The code to display names and allow you to record attendance cannot be designed until you know how the data will be stored. Before anyone can answer your question, the structure of the tables in the database must be known.

Here is some information that might help you determine what you need: http://www.webmasterworld.com/php/3531696.htm

Re: Question in HTML+PHP please helppppp me

Posted: Mon May 19, 2008 6:42 pm
by THE HONY
THanks

<<<you right>>>
my primary language is not english but i try to learn it and explain what i want

1- I have database contains '$student id','$student name'.
2- I want to create php page contains table that columns (id,student name,status,Attendance).
3-the number of rows in table == the number of students stored in databas.
4- then i want to take attednance for every student by checkbox.
5- after i take attendance ,i well send iformation(student id ,student name,attenance) in different table in database.
6- what the way to store information :
if student present ,then store 1 in field 'attendane' otherwise stor '0'

my question:
How i can distinguish between checkboxes values ,to store value in database

THANKS AGAIN

Re: Question in HTML+PHP please helppppp me

Posted: Mon May 19, 2008 8:14 pm
by califdon
It is your second table that I would need to understand. I don't see how a table with only those 3 fields ("studentid, studentname and attendance") would be of any value to you. This is the reason you must design your data structure before you begin to write the script to use the data.

Here is how I would approach your task:

My 2 tables would look like this:

Code: Select all

tblStudents:
   studentid  (primary key)
   studentname
 
tblAttendance:
   attendanceid  (primary key) (auto-increment)
   studentid  (foreign key)
   date_attended
Each record in tblAttendance represents a date on which a particular student attended your class. You do not need any zeroes or ones. Now the only questions should be how to display all your students on the web page, with checkboxes so you can mark attendance, then how to send the studentid numbers of all those who attended, so your second PHP script can insert new records for them into tblAttendance.

To display your web page I would use PHP code like the following (I am leaving out the connection to the database and other formatting details, since I think you already know how to do this):

Code: Select all

...
echo "<form method='post' action='[your 2nd script name]'><table>";
$sql = "SELECT * FROM tblStudents";
$result = mysql_query($sql);
while ($row = mysql_fetch_assoc($result)) {
   extract($row);
   echo "<tr><td>$studentname</td>";
   echo "<td><input type='checkbox' name='$studentid' value='x'></td></tr>";
}
echo "</table>";
echo "<input type='submit' value='Submit Attendance'></form>";
Then, in my second script (named the same as the "action" in the form, above), I would do this:

Code: Select all

...
$today = date("Y-m-d");
foreach ($_POST[] as $sname => $value) {
   $sql = "INSERT INTO tblAttendance SET studentid = '$sname', date_attended = $today";
   mysql_query($sql);
}
Only those checkboxes that have been checked will be submitted, and so all you need to know is for which student, which will be the name of the checkbox. Simple, huh?

There will probably need to be several adjustments to that code, but that is probably the way I would approach the problem.

Re: Question in HTML+PHP please helppppp me

Posted: Mon May 19, 2008 11:03 pm
by califdon
It occurs to me that I neglected to show you how you can recover attendance information from the tables I suggested.

If you wanted to show all students who attended your class on a certain date, you could use this query:

Code: Select all

SELECT studentname 
   FROM tblAttendance 
   LEFT JOIN tblStudents 
   ON tblAttendance.studentid = tblStudents.studentid
   WHERE date_attended = '$mydate'
assuming that $mydate contains a date in the same format as it is stored in the table.

If you wanted to show all dates that a particular student attended your class, you could use this query:

Code: Select all

SELECT studentname, date_attended
   FROM tblStudents
   LEFT JOIN tblAttendance
   ON tblAttendance.studentid = tblStudents.studentid
   WHERE studentname = '$studentname'
 
(or WHERE studentid = '$studentid', if you wanted to refer to the studentid)
again assuming that $studentname or $studentid contains the name or id of the student you wish to display.

You could also run a report of all students and what dates they attended class.

This is the way relational databases work. But you have to design the tables correctly, for this to work.

Re: Question in HTML+PHP please helppppp me

Posted: Tue May 20, 2008 7:44 pm
by THE HONY
thank you my friend for your answers

i ask question about your code:

What about the present students?

Re: Question in HTML+PHP please helppppp me

Posted: Tue May 20, 2008 8:00 pm
by califdon
THE HONY wrote:thank you my friend for your answers

i ask question about your code:

What about the present students?
What about them? What is your question?

Re: Question in HTML+PHP please helppppp me

Posted: Wed May 21, 2008 6:39 pm
by THE HONY
my question?

the your code deal with attendance students

the code store the attendance students in array

how i can store present students in array

Re: Question in HTML+PHP please helppppp me

Posted: Wed May 21, 2008 8:07 pm
by califdon
THE HONY wrote:my question?

the your code deal with attendance students

the code store the attendance students in array

how i can store present students in array
No, I didn't use any arrays in that code. The SQL "INSERT" statement stores data in a table. Perhaps you are asking how to get student data into the table. You would probably want to have a small PHP script with a Form to manage the table, allowing you to add new students, edit a student record (if there was an error) and maybe delete a student record, although generally it is not a good idea to delete records unless they are in error. Good database practice is to keep all valid records in the table as history. I don't have time to write such a script for you, but there must be hundreds of such scripts available as examples, it is one of the most common things that is required for any database. It is referred to as a data entry form.