Jump to content

How I get the values to my third page form.


thara

Recommended Posts

Hello Everyone..

 

Im a programer in php with little experience.

I have a form with 3 pages. 1st page display categories which come from category table. then user can select 1 or upto 3 category there. Then 2nd page display that selected categories and need to display relevant subject to that categories. In second page I use radio button for selected categories to keep a one category as a main category. each categories' subjects display with check boxes. In there too, user can select 1 or 3 more subject in to a particular category. In third form page, that my problem was encounter, there I need to print out  selected category and their subjects in a table.

 

first two pages are no problem for me and third form I have a problem in how to get categories and their subjects and they print as apiece in the page. like this

 

category1 | subject1, subject2, subject3

category2 | subject1, subject2, subject3, subject  and so forth.

 

This same to my first form page

	$q = 'SELECT * FROM category ORDER BY category_id';
$r = mysqli_query( $dbc, $q);
$c = 0;
$i = 0;
echo '<form action="subjects.php" method="post">';
echo '<table class="form_table" ><tr>'; 

while($row = mysqli_fetch_array( $r, MYSQLI_ASSOC  )){

	// if remainder is zero after 2 iterations (for 2 columns) and when $c > 0, end row and start a new row:  
	if( ($c % 2) == 0 && $c != 0){
		echo "</tr><tr>";
	}
	echo '<td width="50%"><input type="checkbox" name="category[]"  value="' . $row['category_id'] . '" />  ' . $row['category_name'] . '</td>';
$c++; 
} // while..
	// in case you need to fill a last empty cell:
	if ( ( $i % 2 ) != 0 ){

	// str_repeat() will be handy when you want more than 2 columns
	  echo str_repeat( "<td> </td>", ( 2 - ( $i % 2 ) ) );
	}
echo "</tr></table>";

?>

 

 

In second page 'subjects.php'  I use

 

	if ( isset($_POST['submitted1']) && isset($_POST['category']) && sizeof( $_POST['category']) == 3 ) { 

	$_SESSION['category'] = $_POST['category']; 

	print_r ( $_SESSION['category']); 

	$q = 'SELECT * FROM category ORDER BY category_id';
	$r = mysqli_query( $dbc, $q);

	while($_SESSION = mysqli_fetch_array( $r, MYSQLI_ASSOC  )){

		foreach( $_POST['category'] as $value ) {

			if ( $value == $_SESSION['category_id']) {

					$q = "SELECT category_subject.category_id, category_subject.subject_id, subjects
							FROM category_subject
							INNER JOIN category ON category_subject.category_id = category.category_id
							INNER JOIN subject ON category_subject.subject_id = subject.subject_id
							WHERE category_subject.category_id = {$_SESSION['category_id']}";

					$r1 = mysqli_query( $dbc, $q);

					$c = $i = 0;

					echo '<table class="form_table" ><tr>'; 

					while($_SESSION = mysqli_fetch_array( $r1, MYSQLI_ASSOC  )){

						// if remainder is zero after 2 iterations (for 2 columns) and when $c > 0, end row and start a new row:  
						if( ($c % 2) == 0 && $c != 0){
							echo "</tr><tr>";
						}
						echo '<td width="50%"><input type="checkbox" name="subject[]"  value="' . $_SESSION['subject_id'] . '" />  ' . $_SESSION['subjects'] . '</td>';

					$c++; 

					} // while..

						// in case you need to fill a last empty cell:
						if ( ( $i % 2 ) != 0 ){

						// str_repeat() will be handy when you want more than 2 columns
						  echo str_repeat( "<td> </td>", ( 2 - ( $i % 2 ) ) );
						}

					echo "</tr></table>";					
			}
		}			
	} 

}

 

 

Those two pages working properly.

 

In third page that my problem page I tried something like this , but its not working.

value come from subject.php page.

 

	if ( ( isset($_POST['submitted2'])) && ( isset($_SESSION['category'])) && (isset( $_SESSION['subjects'])) && sizeof( $_SESSION['category']) == 1) { 

	//$_SESSION['category'] = $_POST['category'];

	print_r ( $_SESSION['category']);

	echo 'good';


} elseif ( ( isset($_POST['submitted2'])) && ( isset($_SESSION['category'])) && 
				(isset( $_POST['main_category'] ))) {

	print_r ( $_SESSION );	


	echo 'very good';

} 

 

So can any body tell me where is my mistake and help me fix this problem.

 

any help greatly appreciated.

 

thank you.

Link to comment
Share on other sites

I am expecting to print out selected categories and its selected subjects. here I have attached my expecting result in the third form. Actually I need know what are the selected categories and their subjects from 2nd page and those values should bring to my 3rd form and display it. Every page I have started the sessions.

 

any help greatly appreciated.

thank you.

post-127605-13482403470372_thumb.jpg

Link to comment
Share on other sites

this attachment shows how my second page is going and how users can select 1 category as main and their subjects. please note: users can select subjects even if it is not the main category. those category come from my first page.

post-127605-13482403470559_thumb.jpg

Link to comment
Share on other sites

  • 2 weeks later...

page1.php page ok it display every category from my database.

 

  echo '<td width="50%"><input type="checkbox" name="category[]"  value="' . $row['category_id'] . '" />  ' . $row['category_name'] . '</td>';

 

 

In my second page I need to display selected categories from 1st page and relevant subjects to that categories.

eg:

cat1 | sub1, sub2, sub3

cat2 | sub1, sub2, sub3,

cat3 | sub1, sub4, sub5 and so on.

 

every category has some subjects and all of those subjects should be display in my second page as category wise. subject also come from my subject table. category_subject table also available to make the relationship between every category and subject. In second page also working as I am expecting. above I have posted my second page coding.

 

But my problem is 3rd page.

 

In second page users can select 3 more subjects to 1 category. assume there is 3 category users can select 9 subjects. so my problem is how I bring those category and their subjects from 2nd page to my 3rd page.

 

actually I am very confusing here and I try to do this for days. unfortunately still I cant get my expecting results.

 

I waiting for any comments and those are greatly appreciated.

 

thank you.

Link to comment
Share on other sites

Ya, you can't set or modify sessions after anything is sent to the browser.  You should have

1. Processing of posts/set sessions/ any header redirect tags header() tags etc

2. html head and body tags

3. visual content/forms etc.

4. close out your page

 

On your pages I don't see item 2, but I do see item 1 and item 3 mixed together.  Work on restructuring things.

 

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.