FRIHOST FORUMS SEARCH FAQ TOS BLOGS COMPETITIONS
You are invited to Log in or Register a free Frihost Account!


PHP/MySQL question





thame
I downloaded this script which is a download counter, and got everything to work properly. Whenever I download the file, I can see the count increasing in PHPMyAdmin.

What I want to do is output the count inside my page.

If you look at the same page, you can see that they have done exactly what I want (maybe not in a table).

Please help me if you can. Thank you!
mathiaus
well would it be on a page with a list of a lot of downloads
eg
Quote:
news - 5467
cms - 67
forum - 25437

if so you can use this code although its odd because the database is purely for the count Mad

Code:
<?php
$dbhost = "localhost";
$dbuser = "user";
$dbpasswd = "pass";
$db_name="dbname";

$db=mysql_connect("$dbhost","$dbuser","$dbpasswd");
mysql_select_db($db_name,$db);
$query="SELECT id, count FROM download";
$result=mysql_query($query);
$num=mysql_numrows($result);
mysql_close();
$i=0;
while ($i < $num) {
$id=mysql_result($result,$i,"id");
$count=mysql_result($result,$i,"count");
$downloads[$id] = $count
$i++;
}
?>


Then to display you can go like this
(assuming the id for news is 1, cms is 2 and forums is 3)
Code:
news - <?php echo $downloads[1]; ?>
<br />cms - <?php echo $downloads[2]; ?>
<br />forums - <?php echo $downloads[3]; ?>


although there are alternative ways this is the best i can think off Smile
Related topics
Reply to topic    Frihost Forum Index -> Scripting -> Php and MySQL

FRIHOST HOME | FAQ | TOS | ABOUT US | CONTACT US | SITE MAP
© 2005-2011 Frihost, forums powered by phpBB.