Du kan bara ha en fråga åt gången i PHP.
$query1 = "SELECT count(*) FROM agents INTO @AgentCount"
$query2="
SELECT user_agent_parsed, user_agent_original, COUNT( user_agent_parsed ) AS thecount,
COUNT( * ) / ( @AgentCount) AS percentage
FROM agents
GROUP BY user_agent_parsed
ORDER BY thecount DESC LIMIT 50";
UPPDATERA
Jag har en DAL som innehåller alla mina frågor. En typisk funktion i min DAL ser ut så här:
// These functions are reusable
public function getAllRows($table)
{
$sql =" SELECT * FROM $table";
$this->query($sql);
return $this->query_result;
}
Sedan i min BLL (Business Layer) har jag följande:
public function getUserAgents()
{
$result = parent::getAllRows();
$row = mysql_fetch_array($result);
return $row[0]; // Retrieves the first row
// Then you take this value and to a second request. Then return the answer / rows.
}