I've added a counter to identify tickboxes and dropdown options in the following code. I am not sure how I can display on the next page the values in the rows where checkboxes are ticked and display the option selected from each dropdown in these rows:
PHP Code:
while ($g = mysql_fetch_assoc($result2)) {
$options .= "<option value='".$g["modcode"]."'>".$g["modcode"]."</option>";
}
...after the loop ends and before the </form> tag?
"Please give us a simple answer, so that we don't have to think, because if we think, we might find answers that don't fit the way we want the world to be."
~ Terry Pratchett in Nation
You're pulling data from a database so I'm guessing you have a unique constraint (auto_increment as the primary key) or something uniquely identifying each row.
I'd use this instead of the $counter variable if possible. Actually that would be essential to this working. =)
On the data display(ing) page...
While checking the POST data from the form submission
PHP Code:
$selectedRows = array();
if( isset( $_POST['FormSubmittingButton'] ) )
{
//first get all selected rows
foreach( $_POST as $key => $value )
{
if( preg_match( "/^booking/", $key )
{
//create a new array index with the
//selected row's index and add a default option value
$selectedRows[ ''. subtring( $key, 7 ) ] = -1; //the '' forces it to be a string
}
}
//now get the option values
foreach( $_POST as $key => $value )
{
if( preg_match( "/^moducode/", $key )
{
//push the selected option value onto the row
//containing the same index
$selectedRows[ ''. subtring( $key, 8 ) ] = $value;
}
}
}
now $selectedRows should be an associative array containing unique IDs and option values for those IDs
I'd then use the information inside $selectedRows to build a sql query, something like this
I don't entirely understand the process above - my form is collecting data from 2 queries, so the unique id will not apply here?. Anyhow, I've tried something similar to your code and it works however on the displaying page, ONLY one row of the rows where a checkbox is selected is displayed. Although when I tested I checked 3 boxes in the form. I think there's a loop or something small missing in my displaying page that will print everything that was selected.
echo "<p>The module you selected is <b>".$_POST[moducode.$counter]."</b>";
echo "<p>The room number you selected is <b>".$_POST[rmnum]."</b>";
echo "<p>The room code you selected is <b>".$_POST[rmcode]."</b>";
echo "<p>The session date you selected is <b>".$_POST[sesdate]."</b>";
echo "<p>The student id you selected is <b>".$_POST[sessid]."</b>";
I was just suggesting using the unique ID's from what you have named the `$result` result set as the indexes of an associative array so that you can cut down on iterating through it but it's not really necessary.
Good point thanks, I've mode the echo "<form>... outside the loop but that didn't make any difference.
I still get the result for one row only, even though 3 rows are ticked
By the way, the row that always get printed is the last row in the form. Does that mean something?
Sorry, I did a few more tests. The result printed is always the last row in the form (even if the checkox is not ticked for that row)
The form contains up to 3 rows depending on the user selection from previous page. I tested with one row, 2 rows and 3 rows. The one row form works fine. But if the form contains 2 or 3 rows, the last row always get displayed even if the checkbox for that row was not selected.
Help please - I am going mad over here. I have a major deadline and spent most of my time working on this issue - I still have a lot more to do
Oh thanks, incrementing the counter now causes the display of as many rows as there are in the form. However, it just repeats the values for the last row. So if there are 2 rows in the form, the last row gets printed twice. If the form has 3 rows, the last row gets printed 3 times (even if the checkbox for it is not ticked)
About sessions, do you mean: s_start_time, s_date, session_id? This data is actually coming from tables they don't have anything to do with php session.
My system is a conference room booking system, each room has sessions associated with it - e.g., 9:00AM (s_start_time) to 12:00PM (s_end_time) on 2006-08-16 (s_date). That's why I had to create the relevant tables for those
Some progress....I think I found where the problem is but I am unable to fix it.
All the rows details from the form are displayed correctly except the session_id and s_start time (thes are the values that are repeated).
I think the problem is in my SQL query! Can you have a look please.
Basically the user selects up to 3 sessions (or none) in a previous page. My SQL query then gets the data for the sessions posted. This is then used in the form above. I think my problem is that the query checks that the session start time entered is ONE of 3, and it does not check if all 3 sessions are entered for example.
This is my code (the rest of it starts from my previously posted code).
PHP Code:
if (!$_POST[s_time1] && !$_POST[s_time2] && !$_POST[s_time3]) {
$query = ("SELECT m_room.r_code, m_room.room_name, m_room_details.r_number, m_session.session_id,
s_date, s_start_time, session_end_time,
room_cost_per_session,
m_room_session.booking_indicator
FROM m_room, m_room_details,
m_room_session, m_session
WHERE m_room.r_code = m_room_details.r_code
AND m_room_session.r_code = m_room_details.r_code
AND m_room_session.r_number = m_room_details.r_number
AND m_room_session.session_id = m_session.session_id
AND m_session.s_date = '".$PostedDate."'
AND m_room.room_name= '".$_POST[s_room]."' ");
}
else {
$query = ("SELECT m_room.r_code, m_room.room_name, m_room_details.r_number, m_session.session_id,
s_date, s_start_time, session_end_time,
room_cost_per_session, m_room_session.booking_indicator
FROM m_room, m_room_details, m_room_session,
m_session
WHERE m_room.r_code = m_room_details.r_code
AND m_room_session.r_code = m_room_details.r_code
AND m_room_session.r_number = m_room_details.r_number
AND m_room_session.session_id = m_session.session_id AND m_session.s_start_time
IN ('".$_POST[s_time1]."', '".$_POST[s_time2]."', '".$_POST[s_time3]."')
AND m_session.s_date = '".$PostedDate."'
AND m_room.room_name= '".$_POST[s_room]."' ");
}
$query2 = ("SELECT student_id, m_module.module_code as
modcode, mod_points FROM m_module, m_student_module
WHERE m_module.module_code = m_student_module.module_code
AND m_student_module.student_id ='".$_SESSION[s_stud_id]."'");
Bookmarks