Jump to content

Recommended Posts

hello..

 

In this script. if part is working properly. but elseif part not working i expect. it display only 1 category and its subjects.

 

Anybody can tell me what the mistake that I have did...

 

Here is my script

 

	} elseif ( isset($_POST['category']) && ( sizeof( $_POST['category']) == 2 || sizeof( $_POST['category']) == 3 )) {

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

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

		foreach( $category as $value ) {

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

				echo '<input type="radio" name="category[]" value="' . $row['category_id'] . '" class="radio" />';
				echo '<label for="" class="radio">  ' . $row['category_name'] . ' <strong>: Mark this category as my "Main Category"</strong></label><br />';

					$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 = {$row['category_id']}";

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

					$c = $i = 0;

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

					while($info = 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="' . $info['subject_id'] . '" />  ' . $info['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>";					
			}
		}			
	}		
} 

Link to comment
https://forums.phpfreaks.com/topic/261478-loop-not-working-properly/
Share on other sites

Its ok now. thanks for your assistance guys!!!

 

Here I use two php page with two forms. my first form is 'sign_up.php' and second is select_subject.php'. sign_up.php page has more categories and users can select up to 3 more categories there. So. after selecting and user click the continue bottom, page want to go to second form page its select_subject.php page.

 

If a user not select a category of who selected over 3 category I need to display a error message. like this  "Please select atleast 1, not more than 3 categories."

 

I use this HTML my first page 

 

<form method="post" action="select_subject.php"> <my select boxes> </form> 

 

Then I process it in my second page and if user have made a mistake in first page I need to redirect to the first page again with relevant error message. So I use this code in my second page.

 

	} else { // No valid ID, kill the script.

	$_SESSION['errors'] = "Please select atleast 1, not more than 3 categories.";

	$url = 'http://localhost/lanka_institute/tutorsignup/tutor_registration.php'; // Define the URL:		
	ob_end_clean(); // Delete the buffer.
	header("Location: $url");
	exit(); // Quit the script.	

}

 

and my first page I use this

 

	if (isset($_SESSION['errors'])) {

	echo '<p> ' . $_SESSION['errors'] . '</p>';

}

unset($_SESSION['errors']);

 

 

but it is not printing my error message in the first page that Im expecting. But it printing 'Array' instead of my message.

 

can you help me, what is the mistake that I have done???

 

thanks in advance.

 

 

 

ya.. this is my header.html file..

 

<?php # header.html

// This page begins the HTML header for the site.

// Start output buffering:

ob_start();

// Initialize a session:

session_start();
?><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" 
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head> 
    
<title><?php echo $page_title;?></title>

<link type="text/css"   rel="stylesheet"   href="../styles/main.css" /> 


</head> 
  
<body> 
  
<div id="header_warp">

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.