Successfully connected to database.
I have a table named "meal" and I am using a code like,
$sql = "SELECT * FROM ( SELECT date, month, day, breakfast, launch, dinner, meal_total, note FROM meal WHERE stid='$_SESSION[stid]' AND ORDER BY date DESC LIMIT 35) sub ORDER BY date DESC";
$result = $dbconnection->query($sql);
I am selecting the rows by, stid='$_SESSION[stid]'
.
The "date
" column records "current timestamp
".
I am using this code to show the values of rows in a HTML table like,
if ($result->num_rows > 0) {
echo "<table >
<tr>
<th>Timestamp</th>
<th>Month</th>
<th>Day</th>
<th>Breakfast</th>
<th>Launch</th>
<th>Dinner</th>
<th>Total Meals</th>
</tr>";
while($row = $result->fetch_assoc()) {
echo "<tr>
<td>" . $row["date"]. "</td>
<td>" . $row["month"]. " </td>
<td>" . $row["day"]. "</td>
<td>" . $row["breakfast"]. "</td>
<td>" . $row["launch"]. "</td>
<td>" . $row["dinner"]. "</td>
<td>" . $row["meal_total"]. "</td>
</tr>";
}
echo "</table>";
} else {
echo "No results!";
}
The code is returning all the rows of the User (as ID). Like,
__________________________________________________________
Year-Month-Date TIME | Nov 2015 | 10 | Others Details ...|
_________________________________________________________
Year-Month-Date TIME | Nov 2015 | 02 | Others Details ...|
__________________________________________________________
Year-Month-Date TIME | Oct 2015 | 15 | Others Details ...|
__________________________________________________________
But the problem is I need to show only the rows from current month. Like,
_________________________________________________________
Year-Month-Date TIME | Nov 2015 | 10 | Others Details ...|
__________________________________________________________
Year-Month-Date TIME | Nov 2015 | 02 | Others Details ...|
__________________________________________________________
Please help me sir. I know there will be a simple trick when selecting rows from my table but I have failed to reveal one as my need. Thanks.