Jump to content

[SOLVED] If - Or


jandrews3

Recommended Posts

I tested the following code and it worked as expected:

if ($var1 == 1 or $var2 == 1) {print "One or both of them was true.";}

 

Shouldn't this also work? It's printing EVERY SINGLE line regardless of whether $m_set or $f_set are empty:

				$count = 0;
				while ($count <= $max){
					if ($m_set[$count] == "" or $f_set[$count] == ""){print "<tr><td>".$student[$count]."-".$count."</td>";}
					if ($m_set[$count] == ""){print "<td>".$mother[$count]."</td>";}
					if ($f_set[$count] == ""){print "<td>".$father[$count]."</td></tr>";}
					$count++;
				}

 

Link to comment
https://forums.phpfreaks.com/topic/118976-solved-if-or/
Share on other sites

Post the whole code with the $m_set and $f_set values. They are arrays right?

 

EDIT: Oh and your code should be better like:

 

<?php
for ($i=0;$i<= $max;$i++) {
   print "<tr>";
   if ($m_set[$i] == "" or $f_set[$i] == ""){print "<td>".$student[$i]."-".$i."</td>";}
   if ($m_set[$i] == ""){print "<td>".$mother[$i]."</td>";}
   if ($f_set[$i] == ""){print "<td>".$father[$i]."</td>";}
   print "</tr>";
}
?>

 

I removed "< tr>" and "< /tr>" from the conditionals, so ure sure u always display them. Using for() instead of while() is just a personal taste :)

Link to comment
https://forums.phpfreaks.com/topic/118976-solved-if-or/#findComment-612653
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.