I have been trying to tackle this problem for many hours. i feel its something as simple as how the if statement should work. Bellow is my code that i am trying to add to: And underneath that code i have typed the php that i tried to use: But i keep getting errors regarding to the structure of the if statement?
Additionally I believe my code itself is at fault, as this error only happens when I insert my code. To confirm this is the pseudo: If sort parameter exists in URL then use the value when selecting the table. Otherwise use the non order sql.
-----------Trying to edit----------
if (isset($_GET[sort])) {
 $sorting = $_GET['sort'];
 $result = $mysqli->query("SELECT * FROM routes ORDER BY $sorting");
}
else {
 $result = $mysqli->query("SELECT * FROM routes");
}
-----------Trying to edit----------
            
 if ($result->num_rows != 0)
 {
  $total_results = $result->num_rows;
  $total_pages = ceil($total_results / $per_page);
  if (isset($_GET['page']) && is_numeric($_GET['page']) && $_GET['page'] <= $total_pages )
   {
   $show_page = $_GET['page'];
                        
   if ($show_page > 0 && $show_page <= $total_pages)
   {
    $start = ($show_page -1) * $per_page;
    $end = $start + $per_page;
   }
   else
   {
     $start = 0;
     $end = $per_page; 
   }               
   }
    else
   {
    $start = 0;
    $end = $per_page;
   }
                
                
               
   echo "<form action='../processors/delete.php' method='post'";
   echo "<br/><table class='table table-striped table-bordered' id='basic-datatable' border='0' cellpadding='10'>";
   echo "<thead><tr> <th>#</th>"; 
   echo "<th><a href='adminviewer.php?sort=route_id'>Route ID</a></th>"; 
   echo "<th><a href='adminviewer.php?sort=route_name'>Route</a></th>"; 
   echo "<th><a href='adminviewer.php?sort=route_price'>Price</a></th>";
   echo "<th><a href='adminviewer.php?sort=route_payment'>Payment</a></th>";
   echo "<th><a href='adminviewer.php?sort=route_net'>Weekly Net</a></th>";
   echo "<th><a href='adminviewer.php?sort=route_city'>City</a></th>";
   echo "<th><a href='adminviewer.php?sort=route_state'>State</a></th>";
      echo "<th><a href='adminviewer.php?sort=route_remarks'>Remarks</a></th>"; 
   echo "</tr></thead>";
   echo "<tbody>";
               
            for ($i = $start; $i < $end; $i++)
   {
    if ($i == $total_results) { break; }
                       
     $result->data_seek($i);
         $row = $result->fetch_row();
               
               
          echo "<tr>";
      echo '<td><input class="checked-box" type="checkbox" name="selec-row[]" value="' . $row[0] . '"></td>';
      echo '<td>' . $row[1] . '</td>';
      echo '<td><a href="detail.php?id=' . $row[0] . '">' . $row[2] . '</a></td>';
      echo '<td>' . $row[3] . '</td>';
      echo '<td>' . $row[4] . '</td>';
      echo '<td>' . $row[5] . '</td>';
      echo '<td>' . $row[6] . '</td>';
      echo '<td>' . $row[7] . '</td>';
      echo '<td>' . $row[8] . '</td>';
      echo "</tr>";
      }
      echo "</tbody>";
      echo "</table>";
      echo "<input class='del-btn' type='submit' value='Delete'>";
      echo "</form>";
            }
            else
            {
             echo "No results to display!";
            }
        
        
      echo '<div class="col-md-12" style="text-align: center;position:relative;top:-25px;">';
      echo "Showing 1 to " . $per_page . " of " . $total_results . " routes";
      echo '</div>';
         
      echo "</div>";
      echo '</div>';
      echo '</div>';
      echo '</div>';
      echo '<div class="pagination">';
      if (!isset($_GET['page'])) {
       $_GET['page'] = 1;
      }
        
      if ($_GET['page'] > $per_page) {
        $next_page = $i - 1;
        echo "<div class='pag-btn'><a href='adminviewer.php?page=$next_page&page_sel=$per_page'><- Previous</a></div>";
      }
      else {
       echo "<div class='pag-btn'>Previous</div>";
      }
      if ($_GET['page'] < $total_pages) {
         $next_page = $_GET['page'] + 1;
         echo "<div class='pag-btn'><a href='adminviewer.php?page=$next_page&page_sel=$per_page'>Next -></a></div>";
      }
      else {
        echo "<div class='pag-btn'>Next</div>";
      }             
      echo '</div>';
            }
           
            else  -----syntax error, unexpected '}'----
            {
             echo "Error: " . $mysqli->error;
            }if(isset($_GET['sort'])) {
  $sorting = sanitize_input($_GET['sort']);
  $result = mysqli->query("SELECT * FROM table ORDER BY $sorting");
} else {
  $result = mysqli->query("SELECT * FROM table ORDER BY id");
}I have looked over the code and i cant see issues with the statement. PHP is telling me errors like unexpected } and when i remove that its like unexpected else etc.
Please share some light on this that would be great, as well as any general structural improvements if you see any :) Error Code: Parse error: syntax error, unexpected '}'
I'm still learning so my critiquing.
Elevant
