Witam, Który kod jest bardziej wydajny oraz jaka jest różnica między tymi dwoma az tak duza?
sposób 1 (mój)
$ChatMessages = $Connect_Server->prepare('SELECT * FROM chat DESC ASC LIMIT 100');
$ChatMessages->execute();
foreach($ChatMessages as $ChatMessage) {
$accounts = $Connect_Server->prepare('SELECT * FROM accounts WHERE id = :account_id LIMIT 1');
$accounts->bindValue(':account_id', $ChatMessage['account_id'], PDO::PARAM_INT);
$accounts->execute();
foreach($accounts as $account){
}
$accounts->closeCursor();
}
$ChatMessages->closeCursor();`
sposób 2 (kolegi)
$QueryGetMessages = $Connect_Server->query('SELECT accounts.user_name, accounts.ranga, accounts.color_name, accounts.color_message, accounts.effect_name, accounts.effect_message, accounts.gender, accounts.avatar, chat.text, chat.create_date FROM accounts INNER JOIN chat ON accounts.id = chat.account_id ORDER BY create_date DESC');
$Messages = $QueryGetMessages->fetchAll(PDO::FETCH_ASSOC);
$Messages = array_reverse($Messages);