diafol
Keep Smiling
10,672 posts since Oct 2006
Reputation Points: 1,632
Solved Threads: 1,514
Skill Endorsements: 57
use mysql_query as advised already.
diafol
Keep Smiling
10,672 posts since Oct 2006
Reputation Points: 1,632
Solved Threads: 1,514
Skill Endorsements: 57
You need to use mysql_fetch_array($result) first. You can't just use the returned resource.
pritaeas
Posting Prodigy
9,316 posts since Jul 2006
Reputation Points: 1,178
Solved Threads: 1,467
Skill Endorsements: 86
The fetch_array gets two lots of results - index-based and numeric-based arrays - by default. Decide which one you want. Anyway the above will work or if you need an association:
$result = mysql_query("SELECT COUNT(`idads`) AS idads FROM `adsmgt`;");
$row = mysql_fetch_assoc($result);
echo $row['idads'];
However, you can limit the fetch_array to one type of array:
$result = mysql_query("SELECT COUNT(`idads`) FROM `adsmgt`;");
$row = mysql_fetch_array($result, MYSQL_NUM); //or MYSQL_ASSOC - default is MYSQL_BOTH
echo $row[0];
diafol
Keep Smiling
10,672 posts since Oct 2006
Reputation Points: 1,632
Solved Threads: 1,514
Skill Endorsements: 57
@davy_yg
The ads counter already works (the script is not listed) - it just the values of idads and time are all 0. idads only to show which ads is counted. Two different ads has to have two different ids.
What is the issue now? Can you explain more? Do you want to select those 2 different ids? Is this the same script that veedeoo posted from the other thread?
LastMitch
Industrious Poster
4,212 posts since Mar 2012
Reputation Points: 134
Solved Threads: 336
Skill Endorsements: 45
@davy_yg
Well in this case, let say I only have one ads. Next time maybe more.
So each ads has an id?
Try this example:
SELECT * FROM adsmgt WHERE id IN (1, 2, 3, 4, 5)
This will select the id that has ads from adsmgt
It's getting late I gotta go
LastMitch
Industrious Poster
4,212 posts since Mar 2012
Reputation Points: 134
Solved Threads: 336
Skill Endorsements: 45
You need to show your code again, to see what you've changed. Include your table structure.
diafol
Keep Smiling
10,672 posts since Oct 2006
Reputation Points: 1,632
Solved Threads: 1,514
Skill Endorsements: 57
a Few things I've picked up...
You have 3 fields in your table freescript - idads, waktu, number. When you insert a record, you do not specify anything for number which will result in a NULL entry.
mysql_query("insert into adsmgt (idads, waktu, number) values ('$idads', '$time', '')");
When you echo out the value of your id's, you need to use the field name...
echo "Number of ad clicks: ".$row['idads'];
If you only want to show how many records there are (which was your original question)...
$result = mysql_query("SELECT * FROM adsmgt");
$num_rows = mysql_num_rows($result);
echo "$num_rows Rows\n";
If you want to show how many records (clicks) for a certain user...
//Assuming you have user id (idads) in memory already and you have it assigned to variable called $user_id...
$result = mysql_query("SELECT * FROM adsmgt WHERE idads='$user_id'");
$num_rows = mysql_num_rows($result);
echo "$num_rows Rows\n";
AndreRet
Industrious Poster
4,706 posts since Jan 2008
Reputation Points: 391
Solved Threads: 481
Skill Endorsements: 20
Yes they do count as values. I was refering to your field "number" in your table freescript which did not get assigned a value.
Not sure what you mean by number for idads, next time maybe $user_id. :)
Did my above code help with your question?
AndreRet
Industrious Poster
4,706 posts since Jan 2008
Reputation Points: 391
Solved Threads: 481
Skill Endorsements: 20