I have upgrade my code. In the old code I had 2 functions: display_maker_success()
and display_maker_fail()
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!
Is better way to do this? I want more code reuse.
function display_maker_success($link, $userid){
$status="closed";
$result="completed";
$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) {
echo "No Record";
} else {
echo "<table border=1>";
echo "<tr><th>Date & Time</th><th>Name</th><th>Status</th></tr>";
while ($row = mysql_fetch_array($result, MYSQL_NUM)) {
echo "<tr><td>$row[0]</td><td>$row[1]</td><td>Completed</td></tr>";
};
echo "</table>";
};
};
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){
echo "No Record";
} else {
echo "<table border=1>";
echo "<tr><th>Date & Time</th><th>Name</th><th>Status</th></tr>";
while ($row = mysql_fetch_array($result, MYSQL_NUM)) {
echo "<tr><td>$row[0]</td><td>$row[1]</td><td>fail</td></tr>";
};
echo "</table>";
};
};
function display_maker_stat ($link, $userid, $reuslt, $limit) {
$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){
echo "No Record";
} else {
echo "<table border=1>";
echo "<tr><th>Date & Time</th><th>Name</th><th>Status</th></tr>";
while ($row = mysql_fetch_array($result, MYSQL_NUM)) {
echo "<tr><td>$row[0]</td><td>$row[1]</td><td>$result</td></tr>";
};
echo "</table>";
};
};