Jump to content

if/else based on $numrows with a condition...is it possible?


cerebrus189

Recommended Posts

Hi all,

I'm wondering if it's possible to use the $numrows boolean parameter where $numrows = 0 and meets a condition.

 

For instance, my code is set up to check for classes where $numrows>0 and then displays the classes. If $numrows < 1, it echoes a message saying there are no classes available and to call the training department. I would like to redirect one of the classes to another link by using a strpos function to search for the classname within the URL. As I understand it, I would have to embed it in the else part of the statement if it's at all possible.

 

Here's what I have so far.

if ($numrows > 0)
{
  echo "<p align=\"left\" class=\"style2 style4\">Click in the check box next to the date for which you would like to register: </p>";
  echo "<p align=\"left\" class=\"style2 style4\">" . $_GET['classname'] . "</p>";
  echo "<table width=100% style=\"color:#FFFFFF\">";
  echo "<th></th>";
  echo "<th>Date</th>";
  echo "<th>Time</th>";
  echo "<th>Location</th>";
  echo "<th>Instructor</th>";
  while ($results = mysql_fetch_array($rs)){
      echo "<tr>";
      echo "<td><input type=\"radio\" name=\"checkbox\" value=\"" . $results['date'] . "|" . $results['time'] . "|" . $results['location'] . "|" . $results['instructor'] . "|" .   $results['course'] . "\"" . "></td>";
      echo "<td class=\"style11\">" . $results['date'] . "</td>";
      echo "<td class=\"style11\">" . $results['time'] . "</td>";
      echo "<td class=\"style11\">" . $results['location'] . "</td>";
      echo "<td class=\"style11\">" . $results['instructor'] . "</td>";
      echo "</tr>";
  }
  echo "</table>";
}
elseif (strpos($_REQUEST['classname'], "BloodBorne Pathogens Video"));
{	
echo "Bloodborne Pathogens is exclusively offered online. Please <a href=../training/online_courses/Bloodborne/BB.html>click here</a> to take the course.";
}
else
{
echo "Please call the training department as there are no classes scheduled at this time."
}

 

Please let me know if this is even possible or if I'm off my rocker. I'm fairly new to the PHP world but not a newb :)

 

Thanks a bunch for your time!

Link to comment
Share on other sites

I figured it out with that little snippet of code added in. Here's the final code.

 

if ($numrows > 0)
{
  echo "<p align=\"left\" class=\"style2 style4\">Click in the check box next to the date for which you would like to register: </p>";
  echo "<p align=\"left\" class=\"style2 style4\">" . $_GET['classname'] . "</p>";
  echo "<table width=100% style=\"color:#FFFFFF\">";
  echo "<th></th>";
  echo "<th>Date</th>";
  echo "<th>Time</th>";
  echo "<th>Location</th>";
  echo "<th>Instructor</th>";
  while ($results = mysql_fetch_array($rs)){
      echo "<tr>";
      echo "<td><input type=\"radio\" name=\"checkbox\" value=\"" . $results['date'] . "|" . $results['time'] . "|" . $results['location'] . "|" . $results['instructor'] . "|" .   $results['course'] . "\"" . "></td>";
      echo "<td class=\"style11\">" . $results['date'] . "</td>";
      echo "<td class=\"style11\">" . $results['time'] . "</td>";
      echo "<td class=\"style11\">" . $results['location'] . "</td>";
      echo "<td class=\"style11\">" . $results['instructor'] . "</td>";
      echo "</tr>";
  }
  echo "</table>";
}
else
{if (strpos($_REQUEST['classname'], "BloodBorne Pathogens Video") !== false){
		echo "Bloodborne Pathogens is exclusively offered online. Please <a href=../training/online_courses/Bloodborne/BB.html>click here</a> to take the course.";
	}
else
{
		echo "Please call the training department.";}
	}

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.