two methods in a class so close in what they do
<p>I have this class that has these two methods that are so closely related to the each other. I do not want to pass the flags so I kept them separate. I was wondering if there is a way to rewrite it so that I do not have to repeat so closely!</p>

<pre><code>  class Test extends Controller
    {
        public static function nonFormattedData($param)
        {
            $arr = array();
            if (is_array($param)) {
                $i = 0;
                $sql = "
                    select *
                    from table1
                    where
                    ";


                if (isset($param['startDate'])) {
                    $sql .= "   date_created between ? AND  ?";
                    $arr[] = $param['startDate'];
                    $arr[] = $param['endDate'];
                    $i++;
                }
                if (isset($param['amount']) &amp;&amp; !empty($param['amount'])) {

                    if ($i &gt; 0) $sql .= " AND ";
                    $sql .= " balance= ?";
                    $arr[] = $param['amount'];
                    $i++;
                }
                if (isset($param) &amp;&amp; !empty($param['amount'])) {

                    if ($i &gt; 0) $sql .= " AND ";
                    $sql .= " balance= ?";
                    $arr[] = $param['amount'];
                    $i++;
                }
                if (isset($param['createdBy']) &amp;&amp; !empty($param['createdBy'])) {

                    if ($i &gt; 0) $sql .= " AND ";
                    $sql .= " column2 like '%Created By: " . $param['createdBy'] . "%'";
                }
                $sql .= ' group by id.table1 ';
                $rs = Query::RunQuery($sql, $arr);
                foreach ($rs as $row) {
                    $records = new Account();
                    $results[] = $records;
                }
                return $results;
            }
        }




        public static function formattedData($serArray, $orderBy = "giftcardaccount_id desc", $offset = 0, $limit = 10)
        {
                $arr = array();
            if (is_array($param)) {
                $i = 0;
                $sql = "
                    select *
                    from table1
                    where
                    ";


                if (isset($param['startDate'])) {
                    $sql .= "   date_created between ? AND  ?";
                    $arr[] = $param['startDate'];
                    $arr[] = $param['endDate'];
                    $i++;
                }
                if (isset($param['amount']) &amp;&amp; !empty($param['amount'])) {

                    if ($i &gt; 0) $sql .= " AND ";
                    $sql .= " balance= ?";
                    $arr[] = $param['amount'];
                    $i++;
                }
                if (isset($param) &amp;&amp; !empty($param['amount'])) {

                    if ($i &gt; 0) $sql .= " AND ";
                    $sql .= " balance= ?";
                    $arr[] = $param['amount'];
                    $i++;
                }
                if (isset($param['createdBy']) &amp;&amp; !empty($param['createdBy'])) {

                    if ($i &gt; 0) $sql .= " AND ";
                    $sql .= " column2 like '%Created By: " . $param['createdBy'] . "%'";
                }
                $sql .= ' group by id.table1 ';
                $rs = Query::RunQuery($sql, $arr);

                return array("data" =&gt; $rs);
            }
        }


    }
</code></pre>
