Jump to content

[SOLVED] creating a rank field, but decrementing values


Recommended Posts

ok, thanks

i basically used that thread's code, and have addapted it do this:




[code]include("inc_files\Database_link.inc");


$rank_query = "SELECT User_Name FROM General_Stats order by Rank DESC";

if ($Rank_Query_Result = mysqli_query($DB_Server, $rank_query)) {
if (mysqli_num_rows($Rank_Query_Result) > 0) {
$current_rank = 1;
while ($row = mysqli_fetch_assoc($Rank_Query_Result)) {
$current_rank++;
}
}
}
[/code]


now thats works fine and its being submitted to the database and all.

BUT when im vewing the database in phpmyadmin, there is never a Rank:2, it goes 1345678...... and so on.???

is it something to do with my loop??? i cant tell.

and one other thing, what does mysqli_fetch_assoc(); do???, i dont understand it
ok, this is the rest of the code:


[code]<?php
include("inc_files\Database_link.inc");


$rank_query = "SELECT User_Name FROM General_Stats order by Rank DESC";

if ($Rank_Query_Result = mysqli_query($DB_Server, $rank_query)) {
if (mysqli_num_rows($Rank_Query_Result) > 0) {
$current_rank = 1;
while ($row = mysqli_fetch_assoc($Rank_Query_Result)) {
$current_rank++;
}
}
}

$User_Name = $_POST['User_Name'];
$Password = $_POST['Password'];
$Email = $_POST['Email'];
$Security_Number = $_POST['Security_Number'];
$F_Name = $_POST['F_Name'];
$L_Name = $_POST['L_Name'];
$Age = $_POST['Age'];
$_POST['Created'] = date("d/m/Y H-i-s");
$Created = $_POST['Created'];
$_POST['Rank'] = $current_rank + 1;
$Rank = $_POST['Rank'];


$to = $Email;
$subject = "New Battle Ages Acccount Confirmation";
$Message = "To ".$F_Name."<br>";
$Message = $Message."User Name :".$User_Name."<br>";
$Message = $Message."Password :".$Password."<br>";
$Message = $Message."Security Number :".$Security_Number."<br><br>";
$Message = $Message."Please type your Security Number into the field below ( with no spaces or dash's), to activate your account";
$Message = $Message."Thankyou for signing up to Battle-Ages.  Please email us a the above address for help and support.<br><br>Yours, Battle-Ages Administraion Team";
$header = "From: admin@battle-ages.itsmyland.com";

$Send_Mail = mail($to, $subject, $Message, $header);




$New_Player_SQL = "INSERT INTO General_Stats
(User_Name, `Password`, Email, Security_Number, F_Name, L_Name, Age, Created, Rank, Level)
VALUES ('$User_Name', '$Password', '$Email', '$Security_Number', '$F_Name', '$L_Name', '$Age', '$Created', '$Rank', '1')";


$New_Player_Query = mysqli_query($DB_Server, $New_Player_SQL)

or die
("<h3>Error</h3>\n<br><br>\n<p>An error has occured while submitting your details to the Database.  As a result your account has not been created, although you may still receive your confirmation email.  If you do receive your Email, please ignore it, and resubmit your account request in 24 hours.</p><br><br>".mysqli_error($DB_Server)."SQL= ".$New_Player_SQL);



echo "<center><h2>Success</h3></center>\n<br><br>\n<p>Your account has been added to our database.  Once you receive your confirmation email, follow the link, and your account will be activated, after which you will be able to play on Battle-Ages whenever you wish.  If however your email only allows text-only emails, then please contact us at admin@battle-ages.itsmyland.com and we will activate your account manually.</p>";
echo "<br><br>";
echo "The Final data that is in the database is :";
echo "<br><br>\n";

echo "User_Name:".$User_Name;
echo "\n<br>\n";
echo "Password: ".$Password;
echo "\n<br>\n";
echo "Email: ".$Email;
echo "\n<br>\n";
echo "Security Number: ".$Security_Number;
echo "\n<br>\n";
echo "First Name: ".$F_Name;
echo "\n<br>\n";
echo "Last Name: ".$L_Name;
echo "\n<br>\n";
echo "Age: ".$Age;
echo "\n<br>\n";



?>
[/code]



thats all of the php..... and the database stuff and everything..... thats all=so the same page ive got the other thread about the smtp error going, if you can help there.... ?
If you insist on going your route at least lets do what you want a little more efficiently. You dont need a loop to get the total number of users in your General_Stats table.

[code=php:0]
if ($result = mysqli_query("SELECT COUNT(*) AS ttl FROM General_Stats")) {
  if (mysqli_num_rows($result) > 0) {
    $row = $row = mysqli_fetch_assoc($result);
    $current_rank = $row['ttl'];
  }
}
[/code]
This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.