1

Can't seem to figure out where my SQL query is incorrect as I have tested each query in phpMyAdmin and they are giving results.

I'm attempting to display this data in a table below as well, but that works fine. The all function seems to be displaying correctly but when I select a month from the drop down menu it gives me the titled error

<?php

$total = 0;
$term1 = 0;
$term2 = 0;

if(isset($_POST["Month"])==null)
{
    $total = mysqli_query($connection,"select count(terminal) from arrivals");
    $term1 = mysqli_query($connection,"select count(terminal) from arrivals where terminal = 't1'");
    $term2 = mysqli_query($connection,"select count(terminal) from arrivals where terminal = 't2'");
}

elseif($_POST["Month"]=="All")
{
    $total = mysqli_query($connection,"select count(terminal) from arrivals");
    $term1 = mysqli_query($connection,"select count(terminal) from arrivals where terminal = 't1'");
    $term2 = mysqli_query($connection,"select count(terminal) from arrivals where terminal = 't2'");
}   

else
{
    //$total = mysqli_query($connection,"select count(terminal) from arrivals where scheduledDate like '%-$months1-%'");
    //$term1 = mysqli_query($connection,"select count(terminal) from arrivals where terminal = 't1' and scheduledDate like '%-$months1-%'");
    //$term2 = mysqli_query($connection,"select count(terminal) from arrivals where terminal = 't2' and scheduledDate like '%-$months1-%'");
}




$row=mysqli_fetch_array($total);
$row1=mysqli_fetch_array($term1);
$row2=mysqli_fetch_array($term2);


print("<table border= 1>");
print("<tr>");
print("<th>");
print("Total Flights");   
print("</th>");
print("<th>");
print($row[0]);
print("</th>"); 
print("</tr>");
print("<tr>");
print("<th>");
print("Terminal 1");   
print("</th>");
print("<th>");
print($row1[0]);
print("</th>"); 
print("</tr>");
print("<tr>");
print("<th>");
print("Terminal 2");   
print("</th>");
print("<th>");
print($row2[0]);
print("</th>"); 
print("</tr>");
print("</table>");
mysqli_close($connection);
?>
Dharman
  • 30,962
  • 25
  • 85
  • 135
MattBerg
  • 33
  • 4
  • Maybe the result set is not returned from the query or the `else` statement is executed. The `else` statement doesn't have any code that can manipulate these three variables. – Wolverine Dec 21 '16 at 16:25
  • You could do this all in one query, or 2. Then since the query is the same remove the `else`s and `if`. – chris85 Dec 21 '16 at 16:25
  • 1
    what's the value of $_POST["Month"]? because isset($var) == null is a*very* weird thing to do,. – Franz Gleichmann Dec 21 '16 at 16:25
  • Please do `print "";` not `print("");` and may more in one line like `print '
    '`; And `isset($_POST["Month"])==null` should be written like `!isset($_POST["Month"])`
    – JustOnUnderMillions Dec 21 '16 at 16:28
  • Note: The [object-oriented interface to `mysqli`](https://www.php.net/manual/en/mysqli.quickstart.connections.php) is significantly less verbose, making code easier to read and audit, and is not easily confused with the obsolete `mysql_query` interface where missing a single `i` can cause trouble. Example: `$db = new mysqli(…)` and `$db->prepare("…")` The procedural interface is an artifact from the PHP 4 era and should not be used in new code. – tadman Apr 28 '20 at 23:49

0 Answers0