2016-11-19 11:38


  • php
  • mysql

I have a problem i hope you can help me out with.

To break it down, i have a table in the database where i create events, it's called "dansetimer" and for that i have a table called for the participants on the events, called "transak"

I want to count how many events within a given time, had more than 20 participants.

I have made this for a start, and it's also very good, but i cant see how to count, how many events i end up with, of course i can just count the list manually, but i really want to get PHP to count it.

    $hentgg = mysql_query("SELECT * FROM dansetimer WHERE dato BETWEEN $fra AND $til"); 
    if(mysql_num_rows($hentgg)) {
    while($visgg = mysql_fetch_array($hentgg)) {

    $result=mysql_query("SELECT count(*) as total FROM transak WHERE produkt = '$visgg[id]'");

    if($data['total'] > 20) {
       echo $visgg[title];  

    } else {
       echo "Ingen resultater";

With the above code i'm able to retrieve the events and get them listed.

With this code:

    $result=mysql_query("SELECT count(*) as total FROM transak WHERE produkt = '$visgg[id]'");

I can count how many participants there are on the event, and with the if statement, testing if there are more than 20, i can hide the events, that dont have more participants.

But do you have a great idea for how i can write "Within the given time, you held 23 events with more than 20 participants" or something like that.

  • 点赞
  • 回答
  • 收藏
  • 复制链接分享