Search the Community
Showing results for tags 'multitable'.
-
Hi, I am trying to produce a result that requires 2 seperate queries to get the values required to produce the result. It works if I hard code the BETWEEN date values but when I try to pull them from the `Reportrange` table no results are returned. I am using includes to set variables, open and close the connection. (also works if BETWEEN dates are hard coded) See below: The idea is that it can search the `DMCstats` table for a count of each distinct 'gender' value WHERE the 'encdate' matches the range set in `Reportrange` record#1(---->bdate and edate) I think the issue is with the way I am calling the variables $bdat , $edat for $result My apologies in advance if this post does not conform to this forums expectations, its my first post here, feel free to enlighten me! Thanks in advance to all those donating their time for the greater good! Open Connection Include: <?php //Conection Info $con=mysqli_connect("localhost","******","******","******"); // Check connection if (mysqli_connect_errno()) echo "Failed to connect to MySQL: " . mysqli_connect_error(); ?> Close Connection Include: <?php mysqli_close($con); ?> Date Variables include: <?php include 'openconnection.php'; $bdat=mysqli_query($con,"SELECT bdate, FROM `ReportRange` WHERE cf_id=1"); $edat=mysqli_query($con,"SELECT edate, FROM `ReportRange` WHERE cf_id=1"); include 'closeconnection.php'; ?> Gender Query: //Open Connection include 'openconnection.php'; //Set Variables include 'datevars.php'; //Query $result=mysqli_query($con,"SELECT gender,encdate, COUNT(gender) AS gender_count FROM `DMC_Stats` WHERE encdate BETWEEN " . $bdat . " AND " . $edat . " GROUP BY gender"); //Output to html echo "<table border='1'> <tr> <th>Gender</th> <th>Total</th> </tr>"; while($row=mysqli_fetch_array($result)) { echo "<tr>"; echo "<td>" . $row['gender'] . "</td>"; echo "<td>" . $row['gender_count'] . "</td>"; echo "</tr>"; } echo "</table>"; //Close connection include 'closeconnection.php'; ?> Regards