[code=php]function aRows($text)
{
if($iadd == 0)
{
echo ‘<table border=”0″ bgcolor=”#CCCCCC”><tr><td>’.$text.'</td></tr></table>’;
$iadd = 1;
}
elseif($iadd == 1)
{
echo ‘<table border=”0″ bgcolor=”#FF0000″><tr><td>’.$text.'</td></tr></table>’;
$iadd = 0;
}
}
And I might execute the following:
[code=php]<?php
aRows(“First row”);
aRows(“Second row”);
aRows(“Third row”);
// etc.
?>
However, it appears my function has a bit of a problem alternating $iadd between 1 and 0.
My code works, if I do not call it in a function:
[code=php]if(!preg_match(“/^[a-zA-Z]+w{5,20}$/”,$d_username))
{
if($iadd == 0)
{
echo ‘<table width=100% border=”0″ bgcolor=”#CCCCCC”><tr><td>’.’Invalid username. Min 5 characters and must start with a letter. No symbols, only underscores.’.'</td></tr></table>’;
$iadd = 1;
}
elseif($iadd == 1)
{
echo ‘<table width=100% border=”0″ bgcolor=”#FFFFFF”><tr><td>’.’Invalid username. Min 5 characters and must start with a letter. No symbols, only underscores.’.'</td></tr></table>’;
$iadd = 0;
}
}
if($d_password == $d_username)
{
if($iadd == 0)
{
echo ‘<table width=100% border=”0″ bgcolor=”#CCCCCC”><tr><td>’.’Username cannot be same as password.’.'</td></tr></table>’;
$iadd = 1;
}
elseif($iadd == 1)
{
echo ‘<table width=100% border=”0″ bgcolor=”#FFFFFF”><tr><td>’.’Username cannot be same as password.’.'</td></tr></table>’;
$iadd = 0;
}
}
However this is quite tiresome and messy, I’m not sure how to make the $iadd variable work in the function, and not sure where to call it. I tried calling it before the function is called, however it returns an ‘undefined variable’ error. I guess the only way is to call it inside the function, however, I am not sure where.