Q:

OOPHP select from MySQL

I am wondering how to do the following I want to create a public function that allows me to do selects from MYSQL
Here is the code I have so far but it brings up a if error.
public function select($table,$options,$where,$orderby)
    {

        $sql = mysql_query("SELECT ". 
        if($options)
        {
        $options
        }
        ." FROM ".
        $table
        if($where)
        {
        ." WHERE ".$where.
        }
        if ($orderby)
        {
        ." ORDER BY ".$orderby.
        }
        ."") or mysql_error() ;

        $row = mysql_fetch_assoc($sql);
        $rows[] = $row;
        print json_encode($rows);

    }

Parse error: syntax error, unexpected T_IF in /home/realcas/public_html/eshop/ecms/system/classes/database.php on line 23

A:

enhanced way:
public function select($table,$options,$where,$orderby)
{
    $options = empty($options) ? "*"   : $options;
    $where  =  empty($where)   ? "1=1" : $where;
    $orderby = empty($orderby) ? ""    : $orderby;

    $qry = "SELECT $options FROM $table WHERE $where $orderby ";
    $result= mysql_query($qry) or die(mysql_error());

    while(($resultArray[] = mysql_fetch_assoc($result));
    return json_encode($resultArray);

}

