Jump to content

[SOLVED] Else statement will not echo


odisey

Recommended Posts

I've written the code to parse a column and create links.  Easy enough.  If ($result) the while statement executes.  Now I am trying to integrate an echo that will execute only if there is NO record retrieved.  Sounds simple.  What am I missing here?  If, elseif, else, nothing is printing.....

 

<?php # Nov 24 2007 Marc Debiase
// Edit Student Records


session_start(); // Access the existing session.
// Include the configuration file for error management and such.

if (isset($_SESSION['user_level']) && ($_SESSION['user_level'] == 1) ) { 
   include('includes/adminHeader.html'); 
     } else { 
   include('includes/header.html'); } 
   
ob_start();


// Check for a valid user ID, through GET or POST.
if ( (isset($_GET['id'])) && (is_numeric($_GET['id'])) ) { // Accessed through view_users.php
$s_id = $_GET['id'];

} elseif ( (isset($_POST['student_number'])) && (is_numeric($_POST['student_number'])) ) { // Form has been submitted.
$s_id = $_POST['student_number'];
} else { // No valid ID, kill the script.
echo '<h1 id="mainhead">Page Error!!</h1>
<p class="error">This page has been accessed in error.</p><p><br /><br /></p>';
include ('includes/footer.html'); 
exit();
}

// Access the existing session.
// Include the configuration file for error management and such.
require_once ('includes/config.inc.php'); 

// Set the page title and include the HTML header.
$page_title = 'Edit  Student Records';


   
	   echo '<h1 id="mainhead">Edit student records</h1><br /><br />';
	   echo '<p>Following is a list of record years and terms containing evaluation data for student ' . $s_id . '.  If you do not see the year and term of data you wish to edit, it is not yet entered into the data base.  Please return to the Enter New Student Record page and enter the data as a new record.</p>';
	   echo '<br /><br />';   


// If no first_name variable exists, redirect the user.
if (!isset($_SESSION['first_name'])) {

// Start defining the URL.
$url = 'http://' . $_SERVER['HTTP_HOST'] . dirname($_SERVER['PHP_SELF']);
// Check for a trailing slash.
if ((substr($url, -1) == '/') OR (substr($url, -1) == '\\') ) {
	$url = substr ($url, 0, -1); // Chop off the slash.
}
// Add the page.
$url .= '/index.php';

ob_end_clean(); // Delete the buffer.
header("Location: $url");
exit(); // Quit the script.

} else {  // MAIN ELSE
      
      require_once ('someDataBase.php'); // Connect to the database.


// $query = "SELECT DISTINCT year FROM student_score WHERE mid_final = '$mf' AND student_id = $s_id ORDER BY year ASC"; 

  $query = "SELECT DISTINCT year as year, mid_final AS mf FROM student_score WHERE student_id = $s_id ORDER BY year ASC"; 


	  $result = @mysql_query($query);
	  
	  if ($result) {


   while ($row = mysql_fetch_array($result, MYSQL_ASSOC)) {

		  	  
	   echo '<p align="left"><a href="editStudentScore.php?student_id=' . $s_id . '&year=' . $row['year'] . '&midterm_final=' . $row['mf'] . '">Edit year ' . $row['year'] .' and term ' . $row['mf'] . '</a></p>'; 
	   
	   echo '<br /><br />';
		  
		  
		  }
		  		  	  
	  }  
	   
	  else {
	  
	 // elseif (!$result) { 
	   
              // if (!isset($result)) {
	  
		  
	   echo '<p>There is no evaluation data entered for student ' . $s_id . '.  Please return to the Enter New Student Record page to enter a new data record for this student.</p>'; }	 
	  
  	  
	  
} // CLOSE MAIN ELSE

	echo '<p>This is a complete list of record years and terms containing evaluation data for student ' . $s_id . '.  Click on the data link you wish to edit.</p>';   
	  
   include ('includes/footer.html');
   
?>



   

 

 

 

Thank you for feedback,

 

Marc

Link to comment
Share on other sites

Give this a try

 

<?php

  $query = "SELECT DISTINCT year as year, mid_final AS mf FROM student_score WHERE student_id = $s_id ORDER BY year ASC"; 
  $result = @mysql_query($query);
	  
      if ($result) {
         if (mysql_num_rows($result) > 0){
      
        while ($row = mysql_fetch_array($result, MYSQL_ASSOC)) {
	  	  
	         echo '<p align="left"><a href="editStudentScore.php?student_id=' . $s_id . '&year=' . $row['year'] . 
               '&midterm_final=' . $row['mf'] . '">Edit year ' . $row['year'] .' and term ' . $row['mf'] . '</a></p>'; 
	   
	         echo '<br /><br />';
		  	  
	}
		  
  } else {
      echo "No Results Found";
  }
		  		  	  
   }  

?>

Link to comment
Share on other sites

I've tried all following ---nothing prints....

 

 
	  $result = @mysql_query($query);
	  
	  if ($result) {


   while ($row = mysql_fetch_array($result, MYSQL_ASSOC)) {

		  	  
	   echo '<p align="left"><a href="editStudentScore.php?student_id=' . $s_id . '&year=' . $row['year'] . '&midterm_final=' . $row['mf'] . '">Edit year ' . $row['year'] .' and term ' . $row['mf'] . '</a></p>'; 
	   
	   echo '<br /><br />';
		  


		  
		   } 
		   
		   		  	  } else {
      echo "No Results Found";

  }
		  		  	  

	   
	//  else {
	  
	 // elseif (!$result) { 
	   
     // if (!isset($result)) {
	  
		  
	  // echo '<p>There is no evaluation data entered for student ' . $s_id . '.  Please return to the Enter New Student Record page to enter a new data record for this student.</p>'; }	 

Link to comment
Share on other sites

$query = "SELECT DISTINCT year as year, mid_final AS mf FROM student_score WHERE student_id = $s_id ORDER BY year ASC"; 
$result = @mysql_query($query);
	  
     if (!isset($result))
    {
       echo "There is no evaluation data entered for student ' . $s_id . '.  Please return to the Enter New Student Record page to enter a new data record for this student";
    }
     else
    {
    // Your code
    }

Link to comment
Share on other sites

I thought that would print....  nope,.... 

 

Do not understand...  With php....    7000 lines of code and one dot in the mix .....  you know...

 

Nope... not yet.

 

TY for the support and ideas....

 

Marc

Link to comment
Share on other sites

I've only had to use 'ob_start()' once and it was short and sweet, yours however is trapped within if statements, and I see no finish to it? But i'm unsure on this usage, so, http://uk3.php.net/manual/en/function.ob-start.php

 

The contents of this internal buffer may be copied into a string variable using ob_get_contents(). To output what is stored in the internal buffer, use ob_end_flush(). Alternatively, ob_end_clean() will silently discard the buffer contents.

 

If you say nothing at all is being printed, just maybe...

Link to comment
Share on other sites

if(!mysql_num_rows($result)) print "no results found";

 

althought you may find supressing your query, wont show an error if it occurs.

meaning you could have an error in your mysql syntax and @mysql_query();

 

is supressing it. try removing the @ and add or die(mysql_error());

 

then see what happens.

Link to comment
Share on other sites

if(!mysql_num_rows($result)) print "no results found";

 

althought you may find supressing your query, wont show an error if it occurs.

meaning you could have an error in your mysql syntax and @mysql_query();

 

is supressing it. try removing the @ and add or die(mysql_error());

 

then see what happens.

 

Sir helper this code resolved it.  I left the @ in place, and code executes. 

 

Thank you!  Thank's for all the input!

 

Marc

 

 

Link to comment
Share on other sites

I've only had to use 'ob_start()' once and it was short and sweet, yours however is trapped within if statements, and I see no finish to it? But i'm unsure on this usage, so, http://uk3.php.net/manual/en/function.ob-start.php

 

The contents of this internal buffer may be copied into a string variable using ob_get_contents(). To output what is stored in the internal buffer, use ob_end_flush(). Alternatively, ob_end_clean() will silently discard the buffer contents.

 

If you say nothing at all is being printed, just maybe...

 

 

Thank's for pointing that out...I've closed the buffer.

 

Marc

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.