Ich habe in meiner Seite 5 Abfragen, die ich nur eine Abfrage haben möchte, wenn es möglich ist, ich weiß nicht, ob es eine bessere Strategie, was ich mache oder es ist in Ordnung.Optimierung mit vielen Abfragen auf Seite
das ist mein Haupt Abfrage, um die Bücher zu laden
$mess = $mysqli->prepare('SELECT * from (SELECT m.id, cm.voteup,
cm.votedown,cr.book_descr FROM books m
INNER JOIN books_vote cm ON cm.bookid = m.id
INNER JOIN book_info cr ON cr.bookid = m.id
WHERE bookid = ? ORDER BY m.date DESC LIMIT 30)ddd
ORDER BY m.date ASC');
$mess->bind_param("i", $book);
$mess->execute();
$mess->store_result();
$mess->bind_result($id,$voteup,$votedown);
while($row = $mess->fetch()){
// im fetching here in this <div class='areabooks'>
}
Dann setze ich die Abfrage in anderen div zu holen mit IF-Bedingung
$mess->data_seek(0);
while($row = $mess->fetch()){
if($voteup - $votedown >= 5){
//I fetch here in this <div class='areabooks2'>
}
}
Dann im the cheking top
MAX(voteup - votedown)
mit dieser Abfrage
$messtop = $mysqli->prepare('SELECT ..........
INNER JOIN ...
INNER JOIN (select id ,MAX(voteup - votedown) as maxe
from books
where voteup - votedown >= 5
group by id ) tt
WHERE bookid = ?
ORDER BY maxe DESC,cm.votedown asc,cm.voteup DESC
limit 1');
$messtop->bind_param("i", $book);
$messtop->execute();
$messtop->store_result();
$messtop->bind_result($id,$voteup,$votedown);
$messtop->fetch();
// then i fetch in this <div class='topbook' >
Dann setze ich die erste Abfrage erneut in anderen div mit IF-Bedingung
$mess->data_seek(0);
while($row = $mess->fetch()){
if($votedown - $voteup >= 5){
//I fetch here in this <div class='areabooks3' >
}
}
Dann holen im die oben
MAX(votedown - voteup)
mit dieser Abfrage bekommen
$messtop = $mysqli->prepare('SELECT ..........
INNER JOIN ...
INNER JOIN (select id ,MAX(votedown - voteup) as maxe
from books where votedown - voteup >= 5
group by id ) tt
WHERE bookid = ?
ORDER BY maxe DESC,cm.voteup ASC,cm.votedown DESC
limit 1');
$messdown->bind_param("i", $book);
$messdown->execute();
$messdown->store_result();
$messdown->bind_result($id,$voteup,$votedown);
$messdown->fetch();
// then i fetch in this <div class='topbottonbook' >
Was im Suchen nach ist, wenn es eine Strategie gibt, um nur eine Abfrage zu verwenden und es in allen diesen divs zu holen, werden diese divs so getrennt.
<first div>
<second div>
<3rd div>
<4th div>
5th div
Wie zu vereinfachen, danke?
Unklar. Sie haben "bookid" ohne Alias und "book_id" mit einem Alias. Sind sie gleich? Bitte haben Sie Aliase für alle Spalten. Und bieten 'SHOW CREATE TABLE' - müssen Indizes sehen, etc. –
@RickJames Entschuldigung, ja sie sind gleich. habe keine Indizes –