Forum Moderators: coopster

Message Too Old, No Replies

Need Help with a php script?

need to have code add max# +1

         

Par5Golf

7:02 am on Nov 13, 2002 (gmt 0)

10+ Year Member



I have a ranking system and when people sign up i want them to go to the bottom of the ranking list...this is what i have....how do i make it so it adds the next # on the list...


<?
if($_SERVER['HTTP_REFERER'])
$THIS_PAGE_URL = $_SERVER['HTTP_REFERER'];
else
$THIS_PAGE_URL = './register.php?sid=' . $ATTSES;

include_once('include/cookie.php');
include_once('include/form_utils.php');

check_vars('Required Fields are missing', 'name', 'email', 'location', 'password');

$MaxRank = one_result_query('SELECT MAX(member_rank) max FROM members');

old_one_query("INSERT into members VALUES ('', '$name', '$email', 1, '$location', '$password', $MaxRank[max], 0)");

Redirect('You are registred, good luck and thanks for joining Par5 Golf', './?sid=' . $ATTSES, 2);

?>

jatar_k

7:49 am on Nov 13, 2002 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



I assume then that you have tried a few things and visited mysql.com and php.net

try this, I didn't test it but I think it works.

$MaxRank = mysql_query('SELECT MAX(member_rank) as max FROM members');
$maxvalue = mysql_fetch_array($MaxRank);
$newvalue = $maxvalue["max"] + 1;

there may be a better way to do it but it's late and I can't think of it now. I also assume that the member_rank is an int column.

jatar_k

7:54 am on Nov 13, 2002 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



from mysql.com on aliasing using AS [mysql.com]

A SELECT expression may be given an alias using AS. The alias is used as the expression's column name and can be used with ORDER BY or HAVING clauses. For example:

mysql> SELECT CONCAT(last_name,', ',first_name) AS full_name
FROM mytable ORDER BY full_name;

# It is not allowed to use a column alias in a WHERE clause, because the column value may not yet be determined when the WHERE clause is executed.