PHP Object Oriented Programming multiple queryes
<p>So, i have this problem. I'm trying my best to practice object oriented programming and I've started with this semi OOP script. How it works, i have one table that's called portal_robot_error witch contains all robot errors. Then i have another main table called portal_robot_service witch is the highest level of the service. Connected to this table i have 2 more that is linked with the portal_robot_service table. These are called portal_service_robot_errorservice and portal_service_robot_changeservice witch contains the details of the service. I hope that I've managed to explain this part good enough!</p>

<p>This is what i want to do. When a user searches for a robot all errors and all services should end in a list ordered by date. </p>

<p>Example: 
User searches for robot 21.
Result:
Error 1 - Date, robot, position, error code etc.
Error 2 - Date, robot, position, error code etc.
Service 1 - Date, robot, service type etc.
Error 3 - Date, robot, position, error code etc.
Error 4 - Date, robot, position, error code etc.
etc...</p>

<p>As the script is now it only shows the errors, how can i show the services in the list?</p>

<p>Thanks in advance!</p>

<pre><code>&lt;?php   
elseif(!empty($query) &amp;&amp; empty($inDate) &amp;&amp; empty($id) &amp;&amp; empty($dateLike)) {
$arr    = array();
$q      = mysql_query("SELECT * FROM portal_robot_error WHERE robot = '$robot'");

while($r = mysql_fetch_object($q)) {

    $m = "Robot ".$r-&gt;robot;
    $s = mysql_query("SELECT * FROM portal_service WHERE service_date &gt;= '$this-&gt;lastService' AND service_date &lt;= '$r-&gt;date' AND service_module = '$m' AND service_id &gt; '$this-&gt;lastId' LIMIT 1");

    if(mysql_num_rows($s) &gt; 0) {
        echo "SELECT * FROM portal_service WHERE service_date &gt;= '$this-&gt;lastService' AND service_date &lt;= '$r-&gt;date' AND service_module = '$m' AND service_id &gt; '$this-&gt;lastId' LIMIT 1&lt;br /&gt;";
        $z              = mysql_fetch_object($s);
        $this-&gt;lastId   = $z-&gt;service_id;

        if($z-&gt;service_type == "Errorservice") {
            $e                      = mysql_query("SELECT * FROM portal_service_robot_errorservice WHERE service_id = '$z-&gt;service_id'");
            $f                      = mysql_fetch_object($e);
            $errorservice_track     = $f-&gt;tracksensor;
            $errorservice_gripper   = $f-&gt;gripper;
            $errorservice_cover     = $f-&gt;cover;
            $errorservice_wheel     = $f-&gt;wheel;
            $service_text           = "Errorservice HIHIHIHI".$this-&gt;lastId;
            $service                = new Error($this-&gt;lastId, $z-&gt;service_date, "", "", $z-&gt;service_module, "", "", $z-&gt;service_type, $z-&gt;service_comment, $service_text, "", $z-&gt;service_user);
            array_push($arr, $service);                     
        }
        elseif($z-&gt;service_type == "Changeservice") {
            $e                      = mysql_query("SELECT * FROM portal_service_robot_changeservice WHERE service_id = '$z-&gt;service_id'");
            $f                      = mysql_fetch_object($e);
            $service_text           = "Changeservice HIHIHIHI".$this-&gt;lastId;
            $service                = new Error($this-&gt;lastId, $z-&gt;service_date, "", "", $z-&gt;service_module, "", "", $z-&gt;service_type, $z-&gt;service_comment, $service_text, "", $z-&gt;service_user);
            array_push($arr, $service);
        }
    }
    else {
        $n   = new Error($r-&gt;error_id, $r-&gt;date, $r-&gt;stoptime, $r-&gt;starttime, $r-&gt;robot, $r-&gt;rob_status, $r-&gt;position, $r-&gt;error_code, $r-&gt;observation, $r-&gt;solution, $r-&gt;downtime, $r-&gt;user);
        array_push($arr, $n);
        $this-&gt;lastService = $r-&gt;date;
    }

}   
return $arr;
}
?&gt;
</code></pre>
