排序变量时出现未知错误

时间:2016-11-01 23:01:50

标签: php html sorting mysqli html-table

我有一张桌子,我设法创建了三个可排序的标题链接中的两个。但是,前两列是相似的,因为它们将数据写为行标记。对于第三列,数据通过我管理的变量显示。该页面完全空白,当我尝试以下代码时,我看不到任何内容。我想我必须为第三列做一些不同的事情,使其工作并排序为前两个。

<?php
    $orderBy = "firstname";
    $order = "asc";

    if(!empty($_GET["orderby"])) {
        $orderBy = $_GET["orderby"];}
    if(!empty($_GET["order"])) {
        $order = $_GET["order"];}

    $postTitleNextOrder = "asc";
    $descriptionNextOrder = "asc";
    $postAtNextOrder = "desc";

    if($orderBy == "post_title" and $order == "asc") {
        $postTitleNextOrder = "desc";}
    if($orderBy == "description" and $order == "asc") {
        $descriptionNextOrder = "desc";}
    if($orderBy == "post_at" and $order == "desc") {
        $postAtNextOrder = "asc";}

    $sql = "SELECT rid, pid, firstname, lastname, email FROM temp_members_db WHERE pid='$pid1' ORDER BY " . $orderBy . " " . $order;
    $result = mysqli_query($mysqli, $sql);
?> 
<table>
          <thead>
        <tr>
        <th><span><a style="color:#ffbf00;" href="?submit=&pid=<?php echo $pid1; ?>&project_name=<?php echo $pname1; ?>&field=firstname&sort=email&orderby=firstname&order=<?php echo $postTitleNextOrder; ?>" class="column-title">Namn</a></span></th>
        <th><span><a style="color:#ffbf00;" href="?submit=&pid=<?php echo $pid1; ?>&project_name=<?php echo $pname1; ?>&field=firstname&sort=email&orderby=email&order=<?php echo $descriptionNextOrder; ?>" class="column-title">E-mail</a></span></th>            
        <th><span><a style="color:#ffbf00;" href="?submit=&pid=<?php echo $pid1; ?>&project_name=<?php echo $pname1; ?>&field=firstname&sort=email&orderby=email&order=<?php echo $postAtNextOrder; ?>" class="column-title">Resultat</a></span></th>
        <th>Radera</th>               
        </tr>
      </thead>
    <tbody>
    <?php
        while($row = mysqli_fetch_array($result)) {
            $count= "SELECT COUNT(qid) AS 'Total' FROM result WHERE rid=".$row['rid']."";
$result01 = mysqli_query($mysqli, $count); 
$resultArr01 = mysqli_fetch_array($result01);
$total= $resultArr01[0]*10;

$pointsummary= "SELECT SUM(points) AS 'Summary' FROM result WHERE rid=".$row['rid']."";
$result02 = mysqli_query($mysqli, $pointsummary);
$resultArr02 = mysqli_fetch_array($result02);
$sum= $resultArr02[0];
$result00 = ($total != 0 ? round($sum/$total*100) : 0);
$color = "#000000";

if (($result00 >= 1) && ($result00 <= 30))
   $color = "#FF0000";
else if (($result00 > 30) && ($result00 <= 60))
   $color = "#FF9900";
else if (($result00 > 60) && ($result00 <= 100))
   $color = "#07d407";

echo "<tr><td><strong>
<form action='respondent2.php' method='GET'>
 <input type='hidden' name='rid' value='".$row['rid']."'>
 <input type='hidden' name='firstname' value='".$row['firstname']."'> 
<input type='submit' class='resname' name='submit' value='".$row['firstname']." ".$row['lastname']."'>
 </form>
 </strong></td> 
 <td>".$row['email']."</td> 
 <td><strong><span style=\"color: $color\">".$result00."</span>%</strong></td>   

 <td><form action='deleterespondent2.php' method='post'>
 <button name='submit' id='byebyeresp' title='Radera kandidat' onclick=\"return confirm('Vill du verkligen radera kandidaten? \\n\\nObservera att kandidatens eventuellt besvarade frågor och resultat raderas också!')\">

 <input type='hidden' name='rid' value='".$row['rid']."'> 
 <img  height='19px' width='19px' src='img/trash.png'>
  </button></form>
 </td></tr>";} 

mysqli_close($mysqli);
?></table>

我无法对由

编写的数据(实际上是数字)进行排序

<td><strong><span style=\"color: $color\">".$result00."</span>%</strong></td>

位于标题链接

之下

<th><span><a style="color:#ffbf00;" href="?submit=&pid=<?php echo $pid1; ?>&project_name=<?php echo $pname1; ?>&field=firstname&sort=email&orderby=email&order=<?php echo $postAtNextOrder; ?>" class="column-title">Resultat</a></span></th>

0 个答案:

没有答案