We're a community of 1077K IT Pros here for help, advice, solutions, professional growth and fun. Join us!
1,076,186 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Start New Discussion Reply to this Discussion

adsmgt

adsmgt.php

$result = mysql_query("SELECT COUNT(idads) AS countidads FROM adsmgt") or die(mysql_error()); 

while($row = mysql_fetch_assoc($result))
{
echo "Number of ad clicks: ".$row['countidads'];

}

$result2 = mysql_query("SELECT waktu, date, time FROM adsmgt") or die(mysql_error());

echo "<br>";
echo "<br>"."Tanggal"."   "."       Waktu"."       Jumlah clicks per hari";

while($row2 = mysql_fetch_array($result2))
{
echo "<br>".$row2['date']."   ".$row2['time'];

}

as of now, all I have is:

Tanggal Waktu Jumlah clicks per hari
2012-11-29 08:51:04
2012-11-29 08:52:00
2012-11-29 08:52:27

I would like to see the number of clicks each day printed out. How to do so? I only see the time and date when it is clicked.

4
Contributors
17
Replies
5 Days
Discussion Span
3 Months Ago
Last Updated
18
Views
davy_yg
Master Poster
730 posts since May 2011
Reputation Points: 10
Solved Threads: 1
Skill Endorsements: 2

@davy_yg

I would like to see the number of clicks each day printed out. How to do so? I only see the time and date when it is clicked.

Can you tell me what option did you try before you post this question? I don't see you post any option what you done. Have you try JOIN or 2 SELECT in one query?

LastMitch
Industrious Poster
4,177 posts since Mar 2012
Reputation Points: 132
Solved Threads: 335
Skill Endorsements: 45

I add this code:

$resultday = mysql_query("SELECT COUNT(idads) AS countidadsday GROUP BY date FROM adsmgt") or die(mysql_error());

while($rowday= mysql_fetch_array($resultday))
{
echo $rowday['countidadsday'];
}

Basically to see how many ads count each day.

Still get this error:
You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'GROUP BY date FROM adsmgt' at line 1

davy_yg
Master Poster
730 posts since May 2011
Reputation Points: 10
Solved Threads: 1
Skill Endorsements: 2

@davy_yg

You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'GROUP BY date FROM adsmgt' at line 1

What is your table? Post your table so we can see what you are doing.

LastMitch
Industrious Poster
4,177 posts since Mar 2012
Reputation Points: 132
Solved Threads: 335
Skill Endorsements: 45

freescript (database)

adsmgt (table) - idads, waktu, number, date, time

davy_yg
Master Poster
730 posts since May 2011
Reputation Points: 10
Solved Threads: 1
Skill Endorsements: 2

@davy_yg

I'm not sure it's gonna work or not. You just want the count right? which is idads?

Try this:

$result = mysql_query("SELECT idads, date, time FROM adsmgt") or die(mysql_error()); 
echo "<br>";
echo "<br>"."Tanggal"." "."  Waktu"." Jumlah clicks per hari";
while($row = mysql_fetch_array($result))
{
echo "<br>".$row['date']."  ".$row['time']"  ".$row['idads'];
}
LastMitch
Industrious Poster
4,177 posts since Mar 2012
Reputation Points: 132
Solved Threads: 335
Skill Endorsements: 45

I mean the count right for each day.

davy_yg
Master Poster
730 posts since May 2011
Reputation Points: 10
Solved Threads: 1
Skill Endorsements: 2

@davy_yg

I mean the count right for each day.

$result = mysql_query("SELECT COUNT(idads) As countidads, date, time FROM adsmgt") or die(mysql_error());

-

Not sure you can try this:

$result = mysql_query("SELECT COUNT(idads) As countidads, waktu, date, time FROM adsmgt") or die(mysql_error());
echo "<br>";
echo "<br>"."Tanggal"." "." Waktu"." Jumlah clicks per hari";
while($row = mysql_fetch_array($result))
{
echo "<br>".$row['date']." ".$row['time']" ".$row['countidads'];
}
LastMitch
Industrious Poster
4,177 posts since Mar 2012
Reputation Points: 132
Solved Threads: 335
Skill Endorsements: 45

Jumlah clicks per hari = number of count for each date

davy_yg
Master Poster
730 posts since May 2011
Reputation Points: 10
Solved Threads: 1
Skill Endorsements: 2

@davy_yg

Jumlah clicks per hari = number of count for each date

Does this code that you post from above works?

$result = mysql_query("SELECT COUNT(idads) AS countidads FROM adsmgt") or die(mysql_error());
while($row = mysql_fetch_assoc($result))
{
echo "Number of ad clicks: ".$row['countidads'];
}
LastMitch
Industrious Poster
4,177 posts since Mar 2012
Reputation Points: 132
Solved Threads: 335
Skill Endorsements: 45

$row['countidads'];

gives me the total ads clicks for all date. Is it possible to print out the countidads for each different date.

davy_yg
Master Poster
730 posts since May 2011
Reputation Points: 10
Solved Threads: 1
Skill Endorsements: 2

i found this on your code
$resultday = mysql_query("SELECT COUNT(idads) AS countidadsday GROUP BY date FROM adsmgt") or die(mysql_error());

basically this displays error because you declare group by before the table name so this should be the proper one

$resultday = mysql_query("SELECT COUNT(idads) AS countidadsday,date, time FROM adsmgt GROUP BY date") or die(mysql_error());

that might solve you problem on displaying the countidaday each different date.

code739
Posting Whiz in Training
208 posts since May 2012
Reputation Points: 17
Solved Threads: 28
Skill Endorsements: 5

gives me the total ads clicks for all date. Is it possible to print out the countidads for each different date.

I think code739 rearrange the query that you post previously and it looks right but I'm not sure if that's what you are asking (Does still print out all the dates?):

$result = mysql_query("SELECT COUNT(idads) AS countidadsday,date, time FROM adsmgt GROUP BY date") or die(mysql_error());
echo "<br>";
echo "<br>"."Tanggal"." "." Waktu"." Jumlah clicks per hari";
while($row = mysql_fetch_array($result))
{
echo "<br>".$row['date']." ".$row['time']" ".$row['countidadsday'];
}
LastMitch
Industrious Poster
4,177 posts since Mar 2012
Reputation Points: 132
Solved Threads: 335
Skill Endorsements: 45

and it depends upon the structure of your table. if your table could store the same date then you could use the group by as what the above post stated.

code739
Posting Whiz in Training
208 posts since May 2012
Reputation Points: 17
Solved Threads: 28
Skill Endorsements: 5

date time Jumlah clicks per hari (Number of clicks per day) turns into:

2013-01-21 07:16:10 4012114112352619

$resultday = mysql_query("SELECT COUNT(idads) AS countidadsday FROM adsmgt GROUP BY date") or die(mysql_error());

while($row = mysql_fetch_assoc($result))
{
echo "Number of ad clicks: ".$row['countidads'];

}

$result2 = mysql_query("SELECT waktu, date, time FROM adsmgt") or die(mysql_error());

echo "<br>";
echo "<br>"."Tanggal"."&nbsp&nbsp&nbsp"."&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbspWaktu"."&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbspJumlah clicks per hari";

while($row2 = mysql_fetch_array($result2))
{
echo "<br>".$row2['date']."&nbsp&nbsp&nbsp".$row2['time']."&nbsp&nbsp&nbsp".$row['countidadsday'];
davy_yg
Master Poster
730 posts since May 2011
Reputation Points: 10
Solved Threads: 1
Skill Endorsements: 2

whats the problem?

code739
Posting Whiz in Training
208 posts since May 2012
Reputation Points: 17
Solved Threads: 28
Skill Endorsements: 5

What a confusing thread to follow!

Your first query is a group by - which is what you're after and you get the counts without any other data

the second query has no group by on it - its just pulling all rows and concatting a var from the last loop which is either not set or is the last value in the last loop.

just add the fields you want to the group by - don't pull time as time will be false(it will be a random time entry from one of the rows in the group)

$resultday = mysql_query("SELECT waktu, date, COUNT(idads) AS countidadsday FROM adsmgt GROUP BY date") or die(mysql_error());
    echo "waktu,date,count<br/>\r\n";
    while($row = mysql_fetch_assoc($result)){
        echo "{$row['waktu']},{$row['date']},{$row['countidadsday']}<br/>\r\n";
    }

If you want the data into an array for random use you can output it into an array with the date as the key - i find it useful for when you are dynamically pulling data and not sure which data will be shown as the data shown is also dynamic.

$resultday = mysql_query("SELECT waktu, date, COUNT(idads) AS countidadsday FROM adsmgt GROUP BY date") or die(mysql_error());
$clicksByDay = array();
while($row = mysql_fetch_assoc($result)){
    $clicksByDay[$row['date']] = $row;
}

echo $clicksByDay['2013-01-17'];

Edit:
Oh and you can use date() to turn into a date or substr() to turn a datetime field into a year,month,day,hour or minute

select date(`date`) FROM...
SELECT SUBSTR(`date`,1,10) as `date`,SUBSTR(`date`,1,7) as `month`,SUBSTR(`date`,1,13) as `hour` FROM...

Remember using a function is much slower than using an indexed field, you'll want to make a separate field and index it on large tables

Biiim
Posting Pro
504 posts since Oct 2011
Reputation Points: 104
Solved Threads: 83
Skill Endorsements: 7

4012114112352619 - wonder how I get this number ?

It suppose to be simpler number (the number of clicks of each specified date).

davy_yg
Master Poster
730 posts since May 2011
Reputation Points: 10
Solved Threads: 1
Skill Endorsements: 2

This article has been dead for over three months: Start a new discussion instead

Post: Markdown Syntax: Formatting Help
 
You
 
© 2013 DaniWeb® LLC
Page rendered in 0.1231 seconds using 2.61MB