Reputation: 63
I am planning to develop a student progress card application using jQuery Mobile and PHP with MySQL database as the back end. This is mainly used by teachers to record the marks of the exam papers they have corrected in the database.
I have a list of students in studentlist.php and a Score Sheet with various subject mark entries in scoresheet.php (Shown Below)
The list of students is extracted from the MySQL db into studentlist.php
Clicking on a list item (say 'Student1') takes you to scoresheet.php.
All the entries made in scoresheet.php needs to be saved in the database for Student 1.
I was wondering, if I can create a value for each list item and pass that variable to scoresheet.php using sessions.
Can some one please help me with a simple example?
Student list will look something similar to this: http://jquerymobile.com/test/docs/lists/lists-divider.html
Scoresheet.php will look something like this:
Student Score Card List
<body>
<div data-role="page" id="page">
<div data-role="header">
<a href="" rel="external" data-ajax="false" data-role="button" data-icon="home" data-theme="b"> Dashboard </a>
<h4> Contractor's List </h4>
</div>
<div data-role="content">
<div data-role="fieldcontain">
<ul data-role="listview" data-inset="true">
<li> <label for="slider-2">Subject1</label>
<input type="range" name="subject1" id="subject1" value="0" min="1" max="10" />
</li>
<li> <label for="slider-2">Subject2</label>
<input type="range" name="subject2" id="subject1" value="0" min="1" max="10" />
</li>
</ul>
</div>
</div>
<div data-role="footer">
<h6>2012 © </h6>
</div>
</div>
</body>
A sample of what I've done by passing variables through URL:
studentlist.php:
<?Php
$sql= 'SELECT student_id, student_name FROM students';
$result=mysql_query($sql);
$num=mysql_num_rows($result);
echo $num;
?>
<div data-role="content">
<div data-role="fieldcontain" data-theme="b">
<ul data-role="listview" data-inset="true">
<li data-role="list-divider"> List of Contractors </li>
<?php
$i=0;
while ($i < $num) {
$f1=mysql_result($result,$i,"student_id");
$f2=mysql_result($result,$i,"student_name");
?>
<li>
<a href="scoresheet.php?id= <?Php echo $f1; ?> ">
<h3> <?Php echo $f2;?> </h3>
</a>
</li>
<?php
$i++;
}
?>
</div>
Now I'll use the variable 'id' in scoresheet.php to update a record in the table using a MySQL query.
Upvotes: 1
Views: 1136
Reputation: 13115
If I understand your question, you have users that are assigned a Session Id. You would like to have a php script file receive Scoresheet updates that retain the Session Id information when making updates.
One easy way to handle it is to drop the session id value into the forms action url.
<form action="scoresheet.php?sessionId=<?php echo $_SESSION['sessionId']; ?>" id="formScoresheet">
However, if you are use the POST method, you may wish to doing something more elegant like placing the session id inside a hidden input.
<input type="hidden" id="sessionId" name="sessionId" value="<?php echo $_SESSION['sessionId']; ?>" />
Check out this example, maybe it will help - http://jsfiddle.net/shanabus/CbkpH/
This all seems a bit redundant though because your server should manage SESSION variables without having to pass them to the page and back. If you are looking for some basic PHP Session examples, you could start here. Basically you have to start the session on the initial request for the studenlist.php
file then be sure to start session before using the values on scoresheet.php
.
Upvotes: 1
Reputation: 1454
Session data can also store more complex data types like multi-dimensional arrays. You could do something like:
$student_id = $_POST['student_id'];
$_SESSION['student_data'][$student_id]['subject_1'] = $_POST['subject_1'];
$_SESSION['student_data'][$student_id]['subject_2'] = $_POST['subject_2'];
Hope that helps.
Upvotes: 1