我一直在用这个工作几个小时,但现在是时候让第二双眼睛来看它......
我有这个mySQL查询:
SELECT
vaktliste.id AS id,
brukere.navn AS bruker,
steder.navn AS sted,
vaktliste.start AS vl_start,
vaktliste.slutt AS vl_slutt,
timeliste.start AS tl_start
FROM brukere, steder, vaktliste
LEFT JOIN timeliste
ON timeliste.sted=vaktliste.sted
AND timeliste.bruker=vaktliste.bruker
AND DATE(timeliste.start)=DATE(vaktliste.start)
WHERE brukere.id=vaktliste.bruker
AND steder.id=vaktliste.sted
AND timeliste.start IS NULL
AND vaktliste.firma=15
AND vaktliste.bruker = 381
AND MONTH(vaktliste.start) = 6
AND YEAR(vaktliste.start) = 2016
ORDER BY vaktliste.start ASC, brukere.navn
当浏览器“运行”时,它没有结果,但在phpMyAdmin中,它得到了一个结果。
当我删除ORDER BY时,我在浏览器中得到了一个结果...
任何人都可以告诉我为什么ORDER BY行会弄乱查询吗?
这是生成查询的PHP文件中的一些代码:
echo("<table id=\"ansatt_tabell\" class=\"ui unstackable celled table\">
<thead>
<tr>
<th>Ansatt</th>
<th>Kunde</th>
<th>Dato</th>
<th>Start</th>
<th>Slutt</th>
<th></th>
</tr>
</thead>
<tbody>");
//Til sammenlangt
$timer_totalt = 0;
$kilometer_totalt = 0;
//Kobler til mySQL-databasen
include("../koble_til_db.php");
//Kjører spørring
$query = "SELECT vaktliste.id AS id, brukere.navn AS bruker, steder.navn AS sted, vaktliste.start AS vl_start, vaktliste.slutt AS vl_slutt, timeliste.start AS tl_start FROM brukere, steder, vaktliste LEFT JOIN timeliste ON timeliste.sted=vaktliste.sted AND timeliste.bruker=vaktliste.bruker AND DATE(timeliste.start)=DATE(vaktliste.start) WHERE brukere.id=vaktliste.bruker AND steder.id=vaktliste.sted AND timeliste.start IS NULL AND vaktliste.firma=$firma";
//Sorterer i henhold til bokser over
if($timeliste_ansatt != 0){
$query = $query . " AND vaktliste.bruker = $timeliste_ansatt";
}
if($timeliste_sted != 0){
$query = $query . " AND vaktliste.sted = $timeliste_sted";
}
if($timeliste_maaned != 0){
$query = $query . " AND MONTH(vaktliste.start) = $timeliste_maaned";
}
if($timeliste_aar != 0){
$query = $query . " AND YEAR(vaktliste.start) = $timeliste_aar";
}
$query = $query . " ORDER BY vaktliste.start ASC, brukere.navn ASC";
$result = mysqli_query($connect, $query);
while($newArray = mysqli_fetch_array($result)){
$id = $newArray['id'];
$bruker = $newArray['bruker'];
$sted = $newArray['sted'];
$start = $newArray['vl_start'];
$start_dato = date('d.m.y', strtotime($start));
$start_tid = date('H:i', strtotime($start));
$slutt = $newArray['vl_slutt'];
$slutt_tid = date('H:i', strtotime($slutt));
//Innhold tabell
echo("<tr>
<td>$bruker</td>
<td>$sted</td>
<td class=\"center aligned\">$start_dato</td>
<td class=\"center aligned\">$start_tid</td>
<td class=\"center aligned\">$slutt_tid</td>
<td class=\"collapsing center aligned\"><div class=\"mini ui green basic button\" onClick=\"adm_timeliste_overfor(this, $id)\">Registrer timer</div></td>
</tr>");
}//while
//Avslutter tabell
echo("</tbody>
收到的错误讯息是:
SELECT将检查超过MAX_JOIN_SIZE行;检查你的WHERE并使用SET SQL_BIG_SELECTS = 1或SET MAX_JOIN_SIZE =#如果SELECT没问题