PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!
Moderator: General Moderators
pedrofilho0
Forum Newbie
Posts: 1 Joined: Tue Oct 11, 2011 4:10 pm
Post
by pedrofilho0 » Tue Oct 11, 2011 4:14 pm
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?
Last edited by
Benjamin on Tue Oct 11, 2011 4:28 pm, edited 1 time in total.
Reason: Added [syntax=php|sql|css|javascript] and/or [text] tags.
social_experiment
DevNet Master
Posts: 2793 Joined: Sun Feb 15, 2009 11:08 am
Location: .za
Post
by social_experiment » Tue Oct 11, 2011 4:54 pm
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)
?>
“Don’t worry if it doesn’t work right. If everything did, you’d be out of a job.” - Mosher’s Law of Software Engineering