Page 1 of 1

help with php code

Posted: Tue Oct 11, 2011 4:14 pm
by pedrofilho0
need some help with this code here

Code: Select all

<?php $i=$start+1;
			foreach($results as $row)
			{
				if($row['branch'] == '0000')
				{
					$brancherror = "error";
				}
				else
				{
					$brancherror = "";
				}
				
				?>

how do I add another one like this to check if another field is greater than 12 characters?

Re: help with php code

Posted: Tue Oct 11, 2011 4:54 pm
by social_experiment

Code: Select all

<?php $i=$start+1;
                        foreach($results as $row)
                        {
                                if($row['branch'] == '0000')
                                {
                                        $brancherror = "error";
                                }
                                elseif (strlen($row['branch'] > 12)
                                {
                                        // statement if condition is met.
                                }
                                else
                                {
                                        $brancherror = "";
                                }
                                
                                ?>
Will a length of greater than 12 characters also result in an error, if so, you can use an OR statement to cut down on code.

Code: Select all

<?php
 if ($row['branch'] == '0000' || strlen($row['branch']) > 12)
?>