Displaying completed and failed wuuks using one or two functions I have upgraded my code. In the old code I had two functions: display_maker_success() and display_maker_fail():

function display_maker_success($link, $userid){
    $status="closed";
    $result="completed";

    $html = '';
    $sql = "select start, name from wuuk where tasker_id ='$userid' and status ='$status' and result ='$result' order by id desc LIMIT 6;";

    $result = mysql_query($sql, $link);
    $isempty=mysql_num_rows($result);
    If ($isempty ==0) {
        $html .= "No Record";
    } else {
        $html .= "&lt;table border=1&gt;";
        $html .= "&lt;tr&gt;&lt;th&gt;Date &amp; Time&lt;/th&gt;&lt;th&gt;Name&lt;/th&gt;&lt;th&gt;Status&lt;/th&gt;&lt;/tr&gt;";
        while ($row = mysql_fetch_array($result, MYSQL_NUM)) {
            $html .= "&lt;tr&gt;&lt;td&gt;$row[0]&lt;/td&gt;&lt;td&gt;$row[1]&lt;/td&gt;&lt;td&gt;Completed&lt;/td&gt;&lt;/tr&gt;";
        };
        $html .= "&lt;/table&gt;";
    };
    echo $html;
};

function display_maker_fail ($link, $userid) {
    $status="closed";
    $result="fail";

    $sql = "select start, name from wuuk where tasker_id ='$userid' and status ='$status' and result ='$result' order by id desc LIMIT 1;";
    $result = mysql_query($sql, $link);
    $isempty=mysql_num_rows($result);
    If($isempty ==0){
        $html .= "No Record";
    } else {
        $html .= "&lt;table border=1&gt;";
        $html .= "&lt;tr&gt;&lt;th&gt;Date &amp; Time&lt;/th&gt;&lt;th&gt;Name&lt;/th&gt;&lt;th&gt;Status&lt;/th&gt;&lt;/tr&gt;";
        while ($row = mysql_fetch_array($result, MYSQL_NUM)) {
            $html .= "&lt;tr&gt;&lt;td&gt;$row[0]&lt;/td&gt;&lt;td&gt;$row[1]&lt;/td&gt;&lt;td&gt;fail&lt;/td&gt;&lt;/tr&gt;";
        };
        $html .= "&lt;/table&gt;";
    };
    echo $html;
};


But I realised I can combine those two functions into one display_maker_stat() by putting more arguments into the function. I like it very much!

function display_maker_stat($link, $userid, $reuslt = 'fail', $limit)
{
    $status = "closed";
    $html = '';
    $sql = "select start, name from wuuk where tasker_id ='$userid' and status ='$status' and result ='$result' order by id desc LIMIT 1;";
    $query = mysql_query($sql, $link);
    if (mysql_num_rows($query) != 0) {
        $html .= "&lt;table border=1&gt;";
        $html .= "&lt;tr&gt;&lt;th&gt;Date &amp; Time&lt;/th&gt;&lt;th&gt;Name&lt;/th&gt;&lt;th&gt;Status&lt;/th&gt;&lt;/tr&gt;";
        while ($row = mysql_fetch_array($query, MYSQL_NUM)) {
            $html.= "&lt;tr&gt;&lt;td&gt;$row[0]&lt;/td&gt;&lt;td&gt;$row[1]&lt;/td&gt;&lt;td&gt;$result&lt;/td&gt;&lt;/tr&gt;";
        }
        $html.= "&lt;/table&gt;";

    }
    else {
        $html.= "No Record";
    }
    echo $html;
}


Is there a better way to do this? I want more code reuse.
I used to do this sort of "optimisation" 20 years ago.  I don't anymore.  Clarity of code is more important.  I would rather have fewer parameters and properly named functions.  This way, you can just read the code without worrying about how the function works.

If you do what you are proposing, then to understand the code, you have to look at the what the function is doing every time it is used !!!

EDIT
An example of what I have just finished doing at work.  The original procedure was called Launch_Client_Form with a whole bunch of parameters.  It had four functions and the parameters of all 4 functions had to be passed each time.  I created 4 procedures


View_Client
Create_Client
Edit_Client
Find_Client


Each one has only the parameters it requires.  Internally they all still call Launch_Client_Form.  Now, when you encounter Edit_Client in the code, it does not require a comment and you know what it is going to do.