I am trying to build a query that will display the Amount of people that signed up in a certain month.

I am adding the date_time to the database at the time someone signs up for a course. I want to display the months and total sign-ups for the month. I code like once every two years so I tend to forget some of this stuff. (Ex: February: 23 people signed up)

If you have any thoughts as to what I can look up and learn for this it would be helpful, Thanks!

if ($result = $db->query("SELECT reg_date, COUNT(reg_date) FROM micro_applicants GROUP BY ('%m')")) {
		
// So the result returned true, let's loop and print out each city.
// The number of rows returned is assigned to the property "num_rows" in the mysql_result class
echo 'Date: '.$result->num_rows.' .
';
// The "fetch_object()" method is the equivalent of the old mysql_fetch_object() function. It allows access to the returned rows within the resouce object ($result in this case).
while ($row = $result->fetch_object()) {
echo '<br /> '.$row->COUNT(reg_date) . $row->COUNT('%m') .  "<br />";
}
} else {
// Notice below that the errors are still contained within the mysqli class. This means that each result will affect a single "error" property. In otherwords, if your result fails, the error returned from MySQL is assigned to the property "error".
// This means the query failed
echo $db->error;
} // end else
$db->close();

Recommended Answers

All 7 Replies

Perhaps this will help:

SELECT YEAR(reg_date) AS `reg_year`, MONTH(reg_date) AS `reg_month`, COUNT(*) AS `reg_count`
FROM micro_applicants 
GROUP BY YEAR(reg_date), MONTH(reg_date)

Wow, That worked perfectly. Now I just need to style it. Thank you for the simple and very helpful tip. Have a great year!

Any thought as to getting the text February, instead of 2 - could I use %m

Wow, That worked perfectly. Now I just need to style it. Thank you for the simple and very helpful tip. Have a great year!

Any thought as to getting the text February, instead of 2 - could I use %m

To answer my own extra thought...

You would change MONTH to MONTHNAME and the month name will print out. Hope that helps...peace

please I need help on this I think it's the same case

<?php
    $getInfo="SELECT favorite.*, COUNT(tutlink) FROM favorite WHERE userid !='".$_SESSION['id']."' AND '".$_SESSION['email']."' = by_user GROUP BY tutname";
    $getResults=$db->query($getInfo)or die($db->error);
    while($Rus = $getResults -> fetch_object()) { 
    echo $Rus->tutname.$Rus->tutname;
    ?>
    <tr>
    <td width="281" style="font-size: 14px; color: rgb(0,51,102);"><?php echo $Rus->tutname;?></td>
    <td width="103"><?php echo $countFav; ?></td>
    <td width="62" align="center"><span style='font-size:14px; color:#003366;'>More</span></td>
    </tr>
    <?php
    }
    ?>



    > 
    > what I need is to echo the results like this 
    > tutorial name       how many times it added to favorite 
    > any tutname                          added 5 times
    > and so on.

Please start a new thread for your question. It would be helpful if you provide additional information on what exactly your problem is, and what is missing from your current code.

@pritaeas how are you dear sir, very happy that you replaed to me I got the answer but I should do what you said the next time.
Thanks again for you replay, have a nice day pritaeas.
Yousef.

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.