to all guru

is this possible
if (($datasex=="F") || ($datasex=="M") )
{
$grabqry .=" (\"$datasex\"==\"$field->sex\" ) ";
}else
{
$grabqry .="";
}

if (eval($grabqry)) //<------ can this be done?? i got an error here
echo "yes";
else
echo "no";

    Try this, eval() returns a null value:

    if (is_null(eval($grabqry))) {
        echo "yes";
    } else {
        echo "no";
    }

      well it wont work

      the code tryin to evaluate as php the string in value $grabqry;

      is there anywork around here

        What won't work? what's the error you are getting.

          Parse error: parse error in c:\inetpub\wwwroot\prog\eval.php(6) : eval()'d code on line 1

          i created a sample code
          $data="M";
          $filed="M";
          $value =" $data==$filed ";
          //(eval(if('$value' ))) echo "yes"; else echo "no";
          if (is_null(eval($value))) {
          echo "yes";
          } else {
          echo "no";
          }

          the output should be YES

            $data="M";
            $filed="M";
            $value = "\$data = \"$filed\";";
            //(eval(if('$value' ))) echo "yes"; else echo "no";
            
            if (is_null(eval($value))) {
            	echo "yes";
            } else {
            	echo "no";
            } 

              well the code that you gave treat only as a value not evaluate as a php

              the simpler code for this "and i want" is

              $data="M";
              $filed="M";
              $value =" $data==$filed ";

              basically we have if then else to compare two strings

              eg: if ($data==$filed) echo "yes"; else echo "no";

              now the comparison is in the variable $value which is ($value=" $data== $filed". Since the queries that im building is too big and there is a if then else . This if then else compose of many comparisons. the comparison coming from the table.

              now I use eval to treat the variable $value not as a value but as a php

              if (eval($value)) should be the same as if ($data==$filed)

                eval doesn't work in a search and replace sort of way. You have to eval a complete snippet of code. You can't use the returned value directly.

                $data="M";
                $filed="M";
                
                $value = '$result = $data == $filed;';
                eval($value);
                if ($result) {
                    echo "yes";
                } else {
                    echo "no";
                }
                

                  Bah, I should've read the manual first. You can treat eval'd code like a function, returning a value, in php4.

                  $data="M";
                  $filed="M";
                  
                  $value = 'return $data == $filed;';
                  if (eval($value)) {
                      echo "yes";
                  } else {
                      echo "no";
                  }
                  

                    ey this works

                    PERFECTTTTTTTTTTTTTTTT

                    thanks men

                      Write a Reply...