Hi Guys,

Im not sure how to word the title of this question, but i have a table called "daily_recyclables". Inside this table, i have multiple columns of recyclable materials (example copper, stainless steel, brass etc etc)

In my PHP application, i have a statistic card (like below) that is supposed to display the total weight of each material in that table based on the current month we are in.

Heres a screenshot of the daily_recylables page to give you an idea: https://ibb.co/sybSC5w

This is my attemp to achieve that which is not working at all, and i do not even know how to make it display based only on entries in the current month automatically.

 <?php
$hostname="localhost";
$username="EXAMPLE";
$password="EXAMPLE";
$db = "EXAMPLE";
$dbh = new PDO("mysql:host=$hostname;dbname=$db", $username, $password);
foreach($dbh->query('SELECT SUM(weight) 
FROM subgrade_bin WHERE subgrade = ?') as $row) {
echo "<tr>";
echo "<td>" . $row['SUM(weight)'] . "</td>". " KG";
echo "</tr>"; 
}
?>

Can someone guide this newby to some resources to assist me on how to do this?

My Table Columns are:
recID (INT AUTO INCREMENT), date,subgrade,castaluminium,copper,stainlesssteel,plastic,batteries,brass,lowgradePCB,mediumgradePCB,highgradePCB.

Hi,

I'm really good with MySQL, but I need some more clarification from you as for what you're trying to do. Unfortunately I woke up with a really bad headache, and so I'm having a hard time understanding while my head is throbbing.

So I'm going to include the screenshot here for everyone to see in case it gets taken down from ibb.co:

ecemsimage.jpg

So you have one table called daily_recyclables ... You say you have multiple columns of materials. I'm assuming you have the columns set up as: recID (INT AUTO INCREMENT), date,subgrade,castaluminium,copper,stainlesssteel,plastic,batteries,brass,lowgradePCB,mediumgradePCB,highgradePCB. Can you please clarify what each row of the table represents? What is a recID?

Your query says SELECT SUM(weight) FROM subgrade_bin WHERE subgrade = ? but what is subgrade_bin??

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.