1
<center>
<?php

$lasttime = $_SERVER['REQUEST_TIME'] - 3600*24*30; // 1 month

Calling to database?

$q = $db->query('SELECT * from votes where lasttime > '.$lasttime);
if($q->num_rows>0)
{
$users = array();
while($r = $q->fetch_object())
{
  $users[$r->username] += 1;
}
if(!empty($users))
{
foreach($users as $user => $t)
{
echo"<br /><strong>$user</strong> has voted $t times";
}
}

If no votes no vote logs.

}else{
echo"NO VOTE LOGS YET";
}


?>
</center>

From what I understand it cant log in to the MYSQL Database? And im not really sure how to do that. Thanks!

PeeHaa
  • 71,436
  • 58
  • 190
  • 262
ilovepie
  • 11
  • 1

2 Answers2

1

$db is not an object, which means the connection failed. You should check if the connection has been established. Assuming you are using mysqli: read this

Shoe
  • 74,840
  • 36
  • 166
  • 272
  • Warning: mysqli::mysqli() [mysqli.mysqli]: (28000/1045): Access denied for user '******'@'site.********.com' (using password: YES) in line 6 Warning: mysqli::query() [mysqli.query]: Couldn't fetch mysqli in on line 7 – ilovepie Jul 26 '12 at 04:10
  • query('SELECT * from votes where lasttime > '.$lasttime); if($q->num_rows>0) { $users = array(); while($r = $q->fetch_object()) { $users[$r->username] += 1; } if(!empty($users)) { foreach($users as $user => $t) { echo"
    $user has voted $t times"; } } }else{ echo"NO VOTE LOGS YET"; } ?>
    – ilovepie Jul 26 '12 at 04:11
  • @ilovepie Access denied for user '***'@'site.*****.com' means that you can't connect with that username and password to the specified database. – Shoe Jul 26 '12 at 09:01
0

Add before line 7...

$db = new mysqli('host','user','password','dbname');
Layton Everson
  • 1,148
  • 9
  • 18