PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!
I am writing a contest script and its all done but the winner part. I am trying to create a script that will run with cron jobs to find the highest voted item, get the user of the item, then find that user in a different table, get his email, and finally write the user and email in a new table. Here is my code. When I run it nothing happens. I'm still new to PHP so I'm sure I am missing a stupid mistake. Can anyone help?
Well, if you look at the code Chinclub posted, max(points) was used, so I would say, Yes.
Chinclub,
1. In your first query you don't select username, so it's not returned in the $row array.
2. Are you sure user and username are the same? Normally I would expect username to be an actual name and user to be an id of the user, maybe.
What are the results of the following (this will help identify the issue):
// This is VERY important when developing/debugging
error_reporting(E_ALL);
ini_set('display_errors', '1');
$sql = mysql_query("SELECT user, max(points) as maxpoints from pets");
while($row = mysql_fetch_array($sql)) {
echo $row['user'];
}
$newsql = mysql_query("SELECT username FROM `members` LIMIT 1");
while($newrow = mysql_fetch_array($newsql)) {
echo $row['username'];
}
Last edited by AbraCadaver on Fri Dec 18, 2009 5:09 pm, edited 1 time in total.
mysql_function(): WARNING: This extension is deprecated as of PHP 5.5.0, and will be removed in the future. Instead, the MySQLi or PDO_MySQLextension should be used. See also MySQL: choosing an API guide and related FAQ for more information.
well what part isn't working? is there an error message?
the first query selects the column points from the row where points is the highest. but then takes that value and assigns it to the variable $user. $user is used to identify the username in the next query. i don't suppose that's what you actually wanted to do is it?
and i thought you are supposed to group items when you use an aggregate function on them?
Well, if you look at the code Chinclub posted, max(points) was used, so I would say, Yes.
Chinclub,
1. In your first query you don't select username, so it's not returned in the $row array.
2. Are you sure user and username are the same? Normally I would expect username to be an actual name and user to be an id of the user, maybe.
What are the results of the following (this will help identify the issue: