Skip to content
Advertisement

Moving from mysql to mysqli – problems

I have the following code:

$query3 = "SELECT 
Office, 
COUNT(Office) As Tot_Part, 
(SELECT COUNT(Office) FROM trespondent WHERE completion_status= 'Started' OR completion_status = 'Complete') As Total_Resp 
FROM trespondent 
WHERE completion_status <> 'New' 
GROUP BY Office 
ORDER BY Office";

$result3 = $mysqli->query($query3);

I am trying to move from mysql to mysqli and am struggling terribly. The above statement brings back only 1 row and not the 26 that there should be. Any pointers welcome.

Advertisement

Answer

That’s because you’re fetching just one row ($los = $result3->fetch_row();).

Try it in a loop.

Like this:

$result3 = $mysqli->query($query3); 
while($los = $result3->fetch_row()) { 
    print_r($los); /* sanity */
}
User contributions licensed under: CC BY-SA
1 People found this is helpful
Advertisement