Php 带变量和限制的订单依据和地点
我有一个带有以下SQL代码的变量,它给了我一个错误(没有“ORDER BY name ASC”,在代码中可以正常工作): 给出下一个错误: 分析错误:语法错误,意外的“按名称排序ASC” (T_常量_包装_字符串)在 有什么办法解决这个问题吗 问候 编辑: 出于上下文目的共享所有代码:Php 带变量和限制的订单依据和地点,php,mysql,sql,Php,Mysql,Sql,我有一个带有以下SQL代码的变量,它给了我一个错误(没有“ORDER BY name ASC”,在代码中可以正常工作): 给出下一个错误: 分析错误:语法错误,意外的“按名称排序ASC” (T_常量_包装_字符串)在 有什么办法解决这个问题吗 问候 编辑: 出于上下文目的共享所有代码: <?php include 'includes/dbh.inc.php'; include 'user_session.php'; // Limit quantity of results per pa
<?php
include 'includes/dbh.inc.php';
include 'user_session.php';
// Limit quantity of results per page
$pageCounter = 10;
// Show number of rows in the table
$sql = "SELECT * FROM incidents WHERE active = 1 AND username = '".$_SESSION['username']."'";
$result = mysqli_query($conn, $sql);
$rowNumbers = mysqli_num_rows($result);
//while ($row = mysqli_fetch_array($result)) {
// echo $row['id'] . " " . $row['username'] . " " . $row['phone'] . "<br>";
//}
// Number of pages available
$numberPages = ceil($rowNumbers/$pageCounter);
// Determine in which page is the user
if (!isset($_GET['page'])) {
$page = 1;
} else {
$page = $_GET['page'];
}
// Determine limit per page
$limitNumber = ($page-1)*$pageCounter;
// Show results
$sql = "SELECT * FROM incidents WHERE active = 1 AND username = '".$_SESSION['username']."' LIMIT " . $limitNumber . "," . $pageCounter " ORDER BY name ASC";
$result = mysqli_query($conn, $sql);
echo "<table>";
echo "<tr><th>Name</th><th>TMC Location</th><th>Non-TMC Location</th><th>Country Code</th><th>Origin Offset</th><th>To Offset</th><th>Start Time</th><th>End Time</th><th>Updated</th><th>Created</th><th>AlertC</th><th>Note</th><th>Group</th><th>Action</th><th>Worked By</th><th>Date</th><th>Incident ID</th><th>Username</th><th>Edit</th><th>Delete</th></tr>";
while ($row = mysqli_fetch_array($result)) {
$id = $row['id'];
$name = $row['name'];
$tmclocation = $row['tmclocation'];
$nontmclocation = $row['nontmclocation'];
$countrycode = $row['countrycode'];
$ooffset = $row['ooffset'];
$toffset = $row['toffset'];
$stime = $row['stime'];
$etime = $row['etime'];
$updated = $row['updated'];
$created = $row['created'];
$alertc = $row['alertc'];
$rcoby = $row['rcoby'];
$note = $row['note'];
$rcogroup = $row['rcogroup'];
$action = $row['action'];
$workedby = $row['workedby'];
$date = $row['rcodate'];
$username = $row['username'];
$incidentid = $row['incidentid'];
echo "<tr><td>".$name."</td><td>".$tmclocation."</td><td>".$nontmclocation."</td><td>".$countrycode."</td><td>".$ooffset."</td><td>".$toffset."</td><td>".$stime."</td><td>".$etime."</td><td>".$updated."</td><td>".$created."</td><td>".$alertc."</td><td>".$note."</td><td>".$rcogroup."</td><td>".$action."</td><td>".$workedby."</td><td>".$date."</td><td>".$incidentid."</td><td>".$username."</td><td><a href='myincidents.php?id=" . $row['id'] ."'>Edit</a></td><td><a id='a_id' href='editor/delete.php?id=" . $row['id'] ."' onClick='return confirm(\"Are you sure?\");'>Delete</a></td></tr>";
}
echo "</table>";
// Display number of pages
for ($page=1; $page <= $numberPages ; $page++) {
echo '<a href="myincidents.php?page=' . $page . '">' . $page . ' </a>';
}
?>
在本部分中,
$pageCounter“按名称订购ASC”
您在$pageCounter
之后缺少
和
订单应在限额之后
因为我们需要先下订单,然后得到结果
试试这个
$sql = "SELECT * FROM incidents WHERE active = 1 AND username = '".$_SESSION['username']."' ORDER BY name ASC LIMIT " . $limitNumber . "," . $pageCounter " ";
执行
限制之前,请先按
订购
$sql = "SELECT * FROM incidents WHERE active = 1 AND username = '".$_SESSION['username']."' ORDER BY name ASC LIMIT " . $limitNumber . "," . $pageCounter " ";
您应该为自己准备一个合适的IDE,它会突出显示语法错误,节省调试时间。您的代码容易受到SQL注入的攻击。您应该使用准备好的语句。现在,给我下一个错误:警告:mysqli_fetch_array()期望参数1是mysqli_result,bool在第44行的C:\xampp\htdocs\rco_development\viewer_user.php中给出,这是该行中的代码:$while($row=mysqli_fetch_array($result)){让我知道,如果分享这个PHP页面中的所有代码更好。显示您的完整代码…完成,对此感到抱歉…谢谢你,我删除了最后2个双引号,它工作得很好,我将在同一条语句中阅读一些关于ORDER BY和LIMIT的文档。
$sql = "SELECT * FROM incidents WHERE active = 1 AND username = '".$_SESSION['username']."' ORDER BY name ASC LIMIT " . $limitNumber . "," . $pageCounter " ";