Ik ben bezig met een berichten systeem maar ik stuit op een probleem... Ik vermoed dat het probleem ligt bij de whileloop waarbij de berichten worden opgehaald, echter weet ik niet hoezo de pagina maarliefst 2.5 seconde nodig heeft om 7 resultaten te laten zien. Ik hoor graag hoe jullie dit zouden aanpakken.
public function listConversationsInbox()
{
$sql = "
SELECT `conversation_id`, `important`
FROM `" . dbPrefix . "conversation_participants`
INNER JOIN `" . dbPrefix . "conversations`
ON `" . dbPrefix . "conversation_participants`.`conversation_id` = `" . dbPrefix . "conversations`.`id`
WHERE `user_id` = '" . $this->getConnection()->escape($_SESSION['id']) . "'
AND (`status` = '0'
OR `status` = '1')
ORDER BY `" . dbPrefix . "conversations`.`created_on` DESC
";
$result = $this->getConnection()->query($sql);
$data = array();
if ($this->getConnection()->num_rows($result) > 0)
{
while($convo = $this->getConnection()->fetch_assoc($result))
{
$sql2 = "
SELECT `created_by`,
`title`,
`status`,
`created_on`
FROM `" . dbPrefix . "conversations`
WHERE `id` = '" . $this->getConnection()->escape($convo['conversation_id']) . "'
LIMIT 1
";
$result2 = $this->getConnection()->query($sql2);
while (
list(
$created_by,
$title,
$status,
$created_on
) = $this->getConnection()->fetch_row($result2)
)
{
$i = count($data);
$data[$i]['number'] = $i;
$data[$i]['id'] = $convo['conversation_id'];
$data[$i]['created_by'] = $this->_user->idToUsername($created_by);
$data[$i]['title'] = $title;
$data[$i]['important'] = $convo['important'];
$data[$i]['status'] = $status;
$data[$i]['created_on'] = $created_on;
if ($status == 1)
{
$data[$i]['icon'] = "fas fa-lock";
}
$sql3 = "
SELECT *
FROM `" . dbPrefix . "conversation_messages`
WHERE `conversation_id` = '" . $this->getConnection()->escape($convo['conversation_id']) . "'
ORDER BY `created_on` ASC
LIMIT 1
";
$result3 = $this->getConnection()->query($sql3);
$data[$i]['message'] = $this->getConnection()->fetch_row($result3);
}
}
}
else
{
$data = false;
}
return $data;
}