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!
I am trying to develop a good utility function and I'm not sure how to get it to work in php. I think I need to use the eval() function but I can't get it to work.
mysql_function(): WARNING: This extension is deprecated as of PHP 5.5.0, and will be removed in the future. Instead, the MySQLi or PDO_MySQLextension should be used. See also MySQL: choosing an API guide and related FAQ for more information.
Is this the best way to go about doing things or is there a better way? What I'm trying to do is create a function that can be called to help with multiple comparisons. In the code examples below I want to be able to multiple comparisons where if any of the conditions are met then a text box would get disabled. Is there a better way to accomplish this or am I on the right track?
Sample code that would call the below function would be:
function Disable()
{
//The arguments should always be in sets of 3 in the format: value1, operator, value2
//The argument between the sets should either be: && (and), || (or)
$numargs = func_num_args();
$arg_list = func_get_args();
$flag = false;
//Make sure that the number of arguments are in sets of three
if($numargs AND 2)
{
for($i=0; $flag == false && $i<$numargs; ++$i)
{
//Check to make sure there is still three arguments to use in the comparison
if(isset($arg_list[$i + 2]))
{
$value1 = $arg_list[$i];
$operator = $arg_list[++$i];
$value2 = $arg_list[++$i];
eval("if($value1 $operator $value2) { \" $flag=true \"; }");
}
}
if($flag)
{
return 'style="background-color:#cfcfcf;" disabled="disabled" ';
}
}
}
mysql_function(): WARNING: This extension is deprecated as of PHP 5.5.0, and will be removed in the future. Instead, the MySQLi or PDO_MySQLextension should be used. See also MySQL: choosing an API guide and related FAQ for more information.