PHP - Help With Ranking System, Selecting A Rank Between 2 Values
hi i have a table like this
rank xp 1 0 2 50 3 100 4 200 say my username has 75xp how would a select which rank i am not sure how i can do this? :S cheers matt Similar TutorialsHello everyone... My following code is supposed to order rank by from Greatest covertaction but for some reason it is ranking the greatest last eg. 900,000 Rank 1 900,001 Rank 2 900,002 Rank 3 Here is the code: Code: [Select] <?php $q = "SELECT * FROM `accountinfo_db` ORDER BY `covertaction`, `anticovertaction` ASC"; $res = mysql_query($q) or die(mysql_error()); $i = 1; while($player=mysql_fetch_array($res)){ $id = securevar($player['id']); $time = time(); $user = securevar($player['username']); $q = "UPDATE `accountinfo_db` SET `covertrank` = '$i', `lastTurnTime` = '$time' WHERE `id` = '$id'"; if(mysql_query($q)){ echo "Covert & Anti Covert Rank set to $user as ".number_format($i)."!<br />"; } else { // query failed with an error // put your error reporting/logging code here... } $i++; } ?> Any help will be appreciated! Brian Hello, I'm in need of assistance trying to get this PHP Script working and I'm hoping you'll be able to find a solution. SQL Table Format: http://pastebin.com/LUuu2pLp Code: [Select] -- -- Table structure for table `hungergames_records` -- CREATE TABLE IF NOT EXISTS `hungergames_records` ( `user_id` int(10) unsigned NOT NULL, `victories` int(32) unsigned NOT NULL DEFAULT '0', `biggest_kill_streak` int(32) unsigned NOT NULL DEFAULT '0', `most_chests_opened` int(32) unsigned NOT NULL DEFAULT '0', `total_chests_opened` int(32) unsigned NOT NULL DEFAULT '0', `lastlogin` int(32) unsigned NOT NULL DEFAULT '0', `longest_lifespan` int(32) unsigned NOT NULL DEFAULT '0', `total_lifespan` int(32) unsigned NOT NULL DEFAULT '0', `total_points` int(32) unsigned NOT NULL DEFAULT '100', `most_points` int(32) unsigned NOT NULL DEFAULT '0', PRIMARY KEY (`user_id`) ) ENGINE=MyISAM DEFAULT CHARSET=latin1; -- -------------------------------------------------------- -- -- Table structure for table `hungergames_users` -- CREATE TABLE IF NOT EXISTS `hungergames_users` ( `id` int(10) unsigned NOT NULL AUTO_INCREMENT, `donor` int(32) unsigned NOT NULL DEFAULT '0', `user` varchar(40) NOT NULL, `donor_cooldown` int(100) unsigned NOT NULL DEFAULT '0', PRIMARY KEY (`id`), UNIQUE KEY `user` (`user`) ) ENGINE=MyISAM DEFAULT CHARSET=latin1 AUTO_INCREMENT=12641 ; PHP Code: http://pastebin.com/aQANz0BL Code: [Select] <?php include("config.php"); $getRankQuery = "SELECT hungergames_users.id, hungergames_records.user_id, hungergames_records.victories, hungergames_records.biggest_kill_streak, hungergames_records.most_chests_opened, hungergames_records.total_chests_opened, hungergames_records.lastlogin, hungergames_records.longest_lifespan, hungergames_records.total_lifespan, hungergames_records.total_points, hungergames_records.most_points, hungergames_users.donor, hungergames_users.user FROM hungergames_records, hungergames_users WHERE hungergames_records.user_id = hungergames_users.id ORDER BY hungergames_records.total_points DESC"; $getRankResult = mysql_query($getRankQuery); //Source From: http://stackoverflow.com/questions/7704311/calculate-rank-with-points function getUserRank($searchedUserID) { $userArray = getAllUsersOrderedByPoints(); $rank = 0; $lastPoints = -1; // Never happens foreach ( $userArray as $user) { if ($user['total_points'] != $lastPoints) $rank++; if ($user['user_id'] == $searchedUserID) break; } return $rank; } while ($data = mysql_fetch_array($result)) { echo getUserRank($data["user_id"]); } ?> What am I trying to accomplish? Simple Ranking System... Basically, The total points is stored into total_points field for each user and whoever has the highest score will be Ranked #1 and count down to a the full database (Currently at 12,641 users) Now the above function getUserRank is the code I pulled from the above source listed, I think my issue relies in the function of getAllUsersOrderedByPoints(); - I've tried doing something like. Code: [Select] $row = mysql_fetch_array($getRankResult); Then adding: $userArray = $row["user_id"]; Didn't work - So if you can help me correct this than I'll be greatly appertiated. Lastly, I've tried doing: Code: [Select] $index = 1; while ($data = mysql_fetch_array($getRankQuery)) { echo $index++ . " " . $data["id"] . " ".$data["user"]." <br>\n"; } This solution works, but this solution would not work for when a "User is Search" it would count them as the highest rank 1,2,3 and wouldn't work, so either the function up there needs to be corrected or please help get a working solution, I've been googleing this issue and seems too be a common code issue with a lot people are having and not many solutions. The application that records data (Not PHP) doesn't store any data with a "Rank" table otherwise this would be a simple echo'ed out data. For a better understanding of what I'm trying to do - You may take a look at: http://justonemoreblock.com/lb/leaderboards.php Regards, Cory Hello everyone... I made point system that ranks users in my app. There are two parts to the system, a primary score and a dynamic score. The primary score is based on how you well you perform and the dynamic score is based on how well your friends perform. Both of these get added together to equal your total score. The problem is that I have a lot of looping occurring which results in about 400 queries being run when I access the page that executes this class. Can this be optimized? What's the best way to do this? I don't want to store the data as I want this presented in real-time. Code: [Select] <?php class edge { public function get_all_users_edge() { $sql = "SELECT id FROM users WHERE status = 3"; $result = mysql_query($sql) or die(mysql_error()); $ids = array(); while (($row = mysql_fetch_assoc($result)) !== false) { $ids[] = $row; } $all_edges = array(); foreach ($ids as $k => $id) { $edge = $this->get_users_edge($id['id']); $all_edges[$k] = $edge; } return $all_edges; } public function get_users_edge($uid) { $users_primary_edge = $this->get_users_primary_edge($uid); $users_dynamic_edge = $this->get_users_dynamic_edge($uid); return $users_primary_edge + $users_dynamic_edge; } public function get_users_primary_edge($uid) { if (active_id($uid) === false) { return false; } $uid = (int)$uid; $sql = "SELECT CHAR_LENGTH(`users`.`credentials`) AS `cred_chars`, CHAR_LENGTH(`users`.`specialties`) AS `spec_chars`, `companies`.`companyvideo` AS `video`, `investor_info`.`accredited` AS `accredited`, ( SELECT COUNT(`user_id`) FROM `blog_posts` WHERE `user_id` = '${uid}' ) AS `post_count`, ( SELECT COUNT(`uid`) FROM `votes` WHERE `uid` = '${uid}' ) AS `vote_sent_count`, `votes_received`.`inv_vote_received_count`, `votes_received`.`pub_vote_received_count`, ( SELECT COUNT(`userid`) FROM `employees` WHERE `userid` = '${uid}' ) AS `joined_count`, `votes2`.`ent_count`, `votes2`.`inv_count`, ( SELECT COUNT(`company_id`) FROM `company_fans` LEFT JOIN `companies` ON `company_fans`.`company_id` = `companies`.`companyid` LEFT JOIN `employees` ON `employees`.`companyid` = `companies`.`companyid` WHERE `userid` = '${uid}' ) AS `company_fans_count`, ( SELECT COUNT(`user_id`) FROM `recommendations` WHERE `user_id` = '${uid}' ) AS `recommendation_count`, ( SELECT COUNT(`partner_id`) FROM `partners` WHERE (`user_id` = '${uid}' OR `friend_id` = '${uid}') AND `approved` = '1' ) AS `associate_count` FROM `users` LEFT JOIN `investor_info` ON `investor_info`.`uid` = `users`.`id` LEFT JOIN `employees` ON `employees`.`userid` = `users`.`id` LEFT JOIN `companies` ON `employees`.`companyid` = `companies`.`companyid` LEFT JOIN ( SELECT `employees`.`userid`, SUM( IF( `votes`.`vote_type` = 1, 1, 0 ) ) AS `inv_vote_received_count`, SUM( IF( `votes`.`vote_type` = 0, 1, 0 ) ) AS `pub_vote_received_count` FROM `votes` INNER JOIN `employees` ON `employees`.`companyid` = `votes`.`company_id` WHERE `employees`.`userid` = '${uid}' GROUP BY `employees`.`userid` ) AS `votes_received` ON `votes_received`.`userid` = `users`.`id` LEFT JOIN ( SELECT `beta_keys`.`ref_id`, SUM( IF( `users`.`accounttype` = 1, 1, 0 ) ) AS `ent_count`, SUM( IF( `users`.`accounttype` = 0, 1, 0 ) ) AS `inv_count` FROM `beta_keys` INNER JOIN `users` ON `users`.`id` = `beta_keys`.`userid` WHERE `beta_keys`.`ref_id` = '${uid}' AND `users`.`status` = 3 GROUP BY `users`.`id` ) AS `votes2` ON `votes2`.`ref_id` = `users`.`id` WHERE `users`.`id` = '${uid}'"; $result = mysql_query($sql) or die(mysql_error()); $row = mysql_fetch_assoc($result); $score = 0; if((!empty($row['cred_chars'])) && (!empty($row['spec_chars']))) { $score += 200; } if(!empty($row['video'])) { $score += 50; } if($row['accredited'] == 1) { $score += 100; } $score += (50 * $row['post_count']); $score += (5 * $row['vote_sent_count']); $score += (3 * $row['inv_vote_received_count']); $score += (1 * $row['pub_vote_received_count']); $score += (200 * $row['joined_count']); $score += (40 * $row['ent_count']); $score += (200 * $row['inv_count']); $score += (10 * $row['company_fans_count']); $score += (30 * $row['recommendation_count']); $score += (20 * $row['associate_count']); return $score; } public function get_users_dynamic_edge($uid) { $uid = (int)$uid; $sql = "( SELECT `users`.`id` FROM partners INNER JOIN `users` ON `partners`.`user_id` = `users`.`id` WHERE partners.friend_id = '${uid}' AND `approved` = 1 ) UNION ALL ( SELECT `users`.`id` FROM `partners` INNER JOIN `users` ON `partners`.`friend_id` = `users`.`id` WHERE `partners`.`user_id` = '${uid}' AND `approved` = 1 )"; $result = mysql_query($sql) or die(mysql_error()); $i = 0; $score = 0; while (($row = mysql_fetch_assoc($result)) !== false) { $dynamic_scores[$i] = array( 'uid' => $row['id'], 'score' => $this->get_users_primary_edge($row['id']), ); $i++; } if(!empty($dynamic_scores)) { foreach($dynamic_scores as $k => $dynamic_score) { $score += $dynamic_score['score']; } } return ($score * 0.1); } } ?> Hi I've set-up a multidimensional PHP array from a SQL query which pulls back parcels despatched per item on a daily basis. e.g. Item|Day1|Day2 |Day3|Day4|Day5 1 |100 | 120 | 90 |150 |60 2 |150 | 200 | 80 |90 |100 3 | 1 | 2 | 3 | 4 | 5 I want to be able to assign a ranked value to each day based upon the amount of items sent out each day and put that either into the existing array, or create a new array to which it can reference I want to query the five heighest values in a coloum but the coloum is not the primarykey. i.e: i have a coloum on the end of my table (articles) called views which get updated when ever an article is viewed by adding 1. On anther page i want to be able to view the 5 most viewed articles. I am trying to create an autocomplete form for 'city,state zip' I want to be able to search by either a distinct zip code that will show 'city, state zip' or by distinct city 'city, state' Can anyone tell me how to fix my script? $sql = "SELECT DISTINCT zip,city,state FROM `residential` WHERE `zip` LIKE '$input%' OR `city` LIKE '$input%' OR `state` LIKE '$input%' UNION SELECT DISTINCT city,state,zip FROM `residential` WHERE `zip` LIKE '$input%' OR `city` LIKE '$input%' OR `state` LIKE '$input%' UNION SELECT DISTINCT state,city,zip FROM `residential` WHERE `zip` LIKE '$input%' OR `city` LIKE '$input%' OR `state` LIKE '$input%' LIMIT $limit"; $result = mysql_query($sql); if (!$result || !mysql_num_rows($result)) exit; include_once "headers.php"; echo "<response>"; while ($row = mysql_fetch_array($result)) { $keywords = "$row[city], $row[state] $row[zip]"; echo "<keywords>". $keywords ."</keywords>"; } while ($row = mysql_fetch_array($result)) { $keywords = "$row[city], $row[state]"; echo "<keywords>". $keywords ."</keywords>"; } echo "</response>"; Ok I'm trying to select the pet with the current eggid in the url. That part works fine, but when I try to select more than one color, it gets all messed up. Because I don't know how to do it and I can't find it on the internet anywhere. Code: [Select] $sql = "SELECT * FROM pets WHERE eggid='".$_GET['eggid']."' AND color='blue' OR 'green' OR 'yellow' OR 'red'"; Does anyone know how to do that? Because whenever I put this: Code: [Select] $sql = "SELECT * FROM pets WHERE eggid='".$_GET['eggid']."' AND color='blue' OR color='yellow' OR color='green' OR color='red'"; It gets all messed up. It selects ALL the colors even if the eggid isn't the current eggid. So it displays the colors of all the pets that have those colors.. :/ EDIT: OR is this the only way I can do it: Code: [Select] $sql = "SELECT * FROM pets WHERE eggid='".$_GET['eggid']."' AND color='blue' OR eggid='".$_GET['eggid']."' AND color='green' OR eggid='".$_GET['eggid']."' AND color='yellow' OR eggid='".$_GET['eggid']."' AND color='red'"; I have a sql query similar to below in a .php file.
$sql = "select id,organisation,price from table where category = '$category';
These are the four unique values of the category column for your reference.
"A-t1"
"B-t1"
"C-t1"
"D-t1"
Now I want to create a dropdown list or listbox in .php file with option to select multiple values. If customer selects multiple values, it should fetch query for the selected categories.
E.g. dropdown list should be similar to below :
"A-t1"
"B-t1"
"C-t1"
"D-t1"
If an user selects "A-t1" and "C-t1", it should give output/query for the selected categories.
Hi All ,
I have a small table with 4 fields namely Day_ID, Dues, Last_Visit, Points. where Day_ID is an auto-increment field. The table would be as follows:
Day_ID -- Dues --- Last_Visit --- Points.
1 --------- 900 -------- 1/12 -------- 6
2 --------- 700 -------- 4/12 -------- 7
3 --------- 600 -------- 7/12 -------- 5
4 --------- 600 -------- 9/12 -------- 6
5 --------- 600 -------- 10/12 ------- 6
6 --------- 600 -------- 14/12 ------- 6
So this is the record of a person's visit to say a club. The last row indicates the last date of his visit to the club. His points on this date are 6. Based on this point value of 6 in the last row I want to retrieve all the previous BUT adjoining all records that have the same Points i.e. 6.
So my query should retrieve for me, based on the column value of Points of the last row (i.e. Day_ID - 6 ), as follows:
4 --------- 600 -------- 9/12 -------- 6
5 --------- 600 -------- 10/12 ------- 6
6 --------- 600 -------- 14/12 ------- 6
This problem stated above had been completely resolved, thanks to a lot of help from Guru Barand by this following query :-
$query = "SELECT cv.day_id, cv.dues, cv.last_visit, cv.points FROM clubvisit cv WHERE last_visit >= ( SELECT MAX(last_visit) FROM clubvisit WHERE points <> ( SELECT points as lastpoints FROM clubvisit JOIN ( SELECT MAX(last_visit) as last_visit FROM clubvisit ) as latest USING (last_visit) ) )";I am using this and it works perfectly except that now there is a slight change in the table because the criteria for points is now dependent on more than one column cv.points and is more like cv.points1, cv.points2, cv.points3 etc. So now I need to make a selection based on each of these cv.points columns. As of now I can still get the results by running the query multiple times for each of the cv.points columns ( seperately for cv.points1, cv.points2, cv.points3) and it works correctly. However I am wondering if there is a better way to do this in just one go. This not only makes the code repetitive but also since the queries are interconnected, involves the use of transactions which I wish to avoid if possible. The values that I require for each of the cv.point columns is 1. day_id of the previous / old day on which the cv.points value changed from the current day value, and 2. cv.points on that old/ previous day. So for example if the table is as below: Day_ID -- Dues --- Last_Visit --- Points1 --- Points2. 1 --------- 900 -------- 1/12 ----------- 9 ------------ 5 2 --------- 600 -------- 4/12 ----------- 6 ------------ 6 3 --------- 400 -------- 7/12 ----------- 4 ------------ 7 4 --------- 500 -------- 9/12 ----------- 5 ------------ 8 5 --------- 600 -------- 10/12 ---------- 6 ------------ 8 6 --------- 600 -------- 11/12 ---------- 6 ------------ 8 7 --------- 600 -------- 13/12 ---------- 6 ------------ 7 8 --------- 500 -------- 15/12 ---------- 5 ------------ 7 9 --------- 500 -------- 19/12 ---------- 5 ------------ 7 Then I need the following set of values : 1. day_id1 -- Day 7, points1 ---- 6, days_diff1 -- (9-7 = 2) . // Difference between the latest day and day_id1 2. day_id2 -- Day 6, points2 ---- 8, days_diff2 -- (9-6 = 3) 3. day_id3 -- .... and so on for other points. Thanks all ! Ever since I switched over to pagination, the ranks for the sites have been off. I use to have an $i++ increment that kept the ranks, but now with pagination, it just ranks those on the current page. Is there a way to bypass this? public function grabSites() { //amount of sites $amount = mysql_num_rows(mysql_query("SELECT * FROM sites")); if($amount > 0) { //amount per page $p_page = 13; //track page $start = $_GET['page']; //max_pages $max_pages = $amount / $p_page; //set default if(!$start) $start = 0; //new query $query = mysql_query("SELECT id,title,description,votes,date,outl,site_url FROM sites ORDER BY votes DESC LIMIT $start, $p_page"); while($fetch = mysql_fetch_assoc($query)) { ++$i; $i = $i + $p_page; echo " <div id='post-1' class='post'> <h2 class='title'><font color='white'>#". $i." ".$fetch['title'] ."</font></h2> <div class='entry'> <b>". $fetch['title'] ." currently has ". $fetch['votes'] ." votes. <a href='vote.php?id=". $fetch['id'] ."'>Vote now</a>.</b> <br/><br/> <p>". nl2br(stripslashes($fetch['description'])) ."</p> </div> <p class='meta'><a href='". $fetch['site_url'] ."'>Visit</a></p> </div> "; } //set back and forth variables $previous = $start - $p_page; $next = $start + $p_page; ?> <hr> <center> <?php if(!($start<=0)) echo "<a href='index.php?page=". $previous ."'><<</a>"; $i = 1; for($x = 0; $x < $amount; $x = $x + $p_page) { echo "<a href='index.php?page=". $x ."'> ". $i ." </a>"; $i++; } if(!($start>=$amount-$p_page)) echo "<a href='index.php?page=". $next ."'>>></a></center>"; ?> </center> <?php } else { echo " <div id='post-1' class='post'> <h2 class='title'><a href='#'>Oh NOEZ!</a></h2> <h3 class='date'>". date("M-d-Y") ."</h3> <div class='entry'> <p>There are currently no sites to display!</p> </div> <p class='meta'>View</p> </div> "; } } Consider the following code; Code: [Select] <div class="blockrow"> <table cellpadding="10" align="center" border="0"> <tr> <td> <center> <font size=6>Donation Hall of Fame</font><br><br> <font size=2><b>Anonymous Donations are not Counted</b></font><br><br> <font size=3><a href="/donate">Get on This List</a></font> <br> <br> <?php //database connection $connectdb = mysql_connect ("localhost", "user", "pass") or die ('I cannot connect to the database because: ' . mysql_error()); mysql_select_db ("thatsact_donations"); //query setup $sql = "SELECT * FROM totals ORDER BY donation_total DESC LIMIT 100"; $result = mysql_query($sql) or die(mysql_error()); //initialize container $container = array(); //get entries from db while ($get = mysql_fetch_assoc($result)){ if(!$get[userid]=="0") { $username = "<b><a style=\"color:#00CC00\" href=/member.php/$get[userid]>$get[username]</a></b> donated <b>$$get[donation_total]</b> total so far!"; } $container[] = "<font size=3>$username</font>"; } //combine collected entries $output = implode("<br /><hr>",$container); echo $output; mysql_close($connectdb); ?> </center> </td> </tr> </table> </div> I would like to add a rank number to the container starting with one and going 23456 as each piece is echoed. How might I do this because I am very new to php. Example: 1. Username donated $5...... 2. Username donated $4........ 3. Username donated $3....... Thanks in advance. Hi all, the other I coded a simular script to this which didnt work, so I re coded it but im having a problem with this one aswell, what its meant to do is just change the users rank to what is posted, but every time I hit submit on the form it locates me to a different place. <?php session_start(); include ("../includes/db_connect.php"); include ("../includes/functions.php"); logincheck(); $username = $_SESSION['username']; $rankget = mysql_query ("SELECT * FROM users WHERE username='$username'"); $newrank = mysql_fetch_object($rankget); if ($_POST['change']){ if ($newrank->userlevel >= "2"){ $time = now(); $updateuser = $_POST['usernameone']; // User Posted $updaterank = $_POST['rankone']; // Rank posted if ($updateuser == NULL && $updaterank == NULL){ $message = "You must enter a user and rank"; }elseif ($updateuser == NULL){ $message = "You must enter a username"; }elseif ($updaterank == NULL){ $message = "You must enter a rank"; } mysql_query ("UPDATE users SET rank = '$updaterank' WHERE username='$updateuser'") or die (mysql_error()); mysql_query ("INSERT INTO logs (`id` , `who`, `action`, `time`) VALUES ('', '$username' , '$username Updated rank; $updateuser to $updaterank' , '$time')") or die (mysql_error()); mysql_query ("INSERT INTO inbox (`id` , `to` , `from` , `message` , `date` , `read` , `saved` , `event_id`) VALUES ('', '$updateuser', 'System', 'Your rank has been updated to $updaterank!', '$date', '0', '0', '')") or die (mysql_error()); echo ("Rank Changed!"); }} ?> <html> <head> <title>Change Rank</title> <link rel="stylesheet" href="../include/in.css" type="text/css"> <style type="text/css"> .infobg { font-family: Arial; font-weight:normal; font-size:12px; border-top: 1px solid #000000; border-right: 1px solid #000000; border-bottom: 1px solid #000000; border-left: 1px solid #000000; background: URL(textbg1.png); font-weight:300; } .button { font-size: 12px; background:url(button.png); vertical-align: middle; border-top: 1px solid #000000; border-right: 1px solid #000000; border-bottom: 1px solid #000000; border-left: 1px solid #000000; color: #FFFFCC; height:23px; font-weight:300; border-radius: 10px; padding-bottom:2px; } </style> </head> <body> <form action='' name='form1' id='form1' method='POST'> <table width='50%' cellpadding='0' align='center' cellspacing='0' border='1' bordercolor='#000000' bgcolor='#808080' style='border-collapse: collapse'> <tr> <td><?php echo ("$message"); ?></td> </tr> <tr> <td background='../header.jpg' colspan='2' align='center'>Change Rank</td> <tr> <td>Username:</td><td><input type='text' name='usernameone'></td> </tr> <tr> <td>Rank:</td><td><input type='text' name='rankone'></td> </tr> <tr> <td> </td><td><input type='submit' name='change' value='Change Rank!'></td> </tr> </table> </form> </body> </html> Anyone see why it locates me else? Thanks I am having trouble on user post = rank This is the rank table: ----------------- post | rank ----------------- 0 | Noob 10 | Member 50 | Metal 100 | Silver 200 | Gold $user_post="120"; $query_rank=mysql_query("SELECT * FROM rank WHERE post<='$user_post' OR post>='$user_post'") or die ("Error"); while ($row=mysql_fetch_assoc($query_rank)){ $rank=$row['rank']; } echo "User Rank: $rank"; The above code output: User Rank: Gold The right output should be: User Rank: Silver Please help It will be better if someone willing to share a better ranking code. Hello everyone,
I'm create an application where I have member, admin, and superadmin
What I'm try to do is superadmin update member to admin, so they can have more privilege. The name of the table is member where I have member, admin account, and i have row call 'rank'. Rank 1 is for member they have access basic stuff and rank 2 they have more privilege. Want the superadmin to type the name of the member and change to rank 2.
This is what happening, if I dont put nothing on the text boxes, it said "Please check if you have put the right information." , if i put member and the rank i want to change is says ""User has upgrade to admin", but than when i check my database the member is still a member when i wanted to change to admin.
Can anyone see where I'm going home, or what should I change.
<form> </form> <form action='<?php htmlentities($_SERVER['PHP_SELF']); ?>' method='POST' enctype='multipart/form-data '> Username: <input class="fontsize" name='user' type='text'/> Rank: <input class="fontsize" name='rank' type='text' /> <br><br> <input class="button" type='submit' name='get' value='Upgrade' /> </form> </h2> <?php if(isset($_POST['get'])) { $username1 = $_POST['user']; $sql_user = mysqli_real_escape_string ($connection, $username1); $rank = $_POST['rank']; $rank = mysqli_real_escape_string ($connection, $rank); $query1 = mysqli_query($connection, "SELECT rank FROM member WHERE username='$sql_user'"); if ($row = mysqli_fetch_array($query1)) { if ($rank == '1') { $data1 = mysqli_query($connection, "UPDATE member SET rank= '1' WHERE username='sql_user'") or die (mysql_error($connection)); echo "User has downgrade to member"; } elseif ($rank == '2') { $data2 = mysqli_query($connection, "UPDATE member SET rank= '2' WHERE username ='sql_user'") or die (mysql_error($connection)); echo "User has upgrade to admin"; } else { echo "Please check if you have put the right information."; } } } ?> This topic has been moved to MySQL Help. http://www.phpfreaks.com/forums/index.php?topic=312470.0 I would like to create something like foursquare badges. When ppl upload files, the most downloaded files will have a new badge, how do i create that? I am trying to figure out how to assign a number rank to a set of results, but I need to reset the ranking when a certain column changes. For example: Brand Rank a 1 a 2 a 3 b 1 b 2 b 3 I set $rank=0; and then for each item in my loop I add $rank++; How do I get the rank to reset in the loop when the brand changes? Thanks for any help. Hey guys and girls, Okay so am trying to provide a rank for each user within my database but I cant seem to get it working here is my code Code: [Select] SELECT `Table`.`Id`, `Table`.`Photo`, `Table`.`Fname`, `Table`.`Lname`, `Table`.`Gender`, `Table`.`Gd`, `Table`.`Bd`, `Table`.`Point`, (SELECT COUNT(*) + 1 FROM (SELECT U.Id, T.`User Id` FROM `u_account` U LEFT JOIN `score_system` T ON `T`.`User Id` = `U`.`Id`) x WHERE Table.Point > (SELECT SUM(Good)-SUM(Bad) FROM `score_system` GROUP BY `User Id`) ) AS RANK FROM (SELECT `C`.`Id`, `C`.`Photo`, `C`.`Fname`, `C`.`Lname`, `C`.`Gender`, CASE WHEN COALESCE( SUM(`S`.`Good`), '') = '' THEN '0' ELSE SUM(`S`.`Good`) END AS Gd, CASE WHEN COALESCE( SUM(`S`.`Bad`), '') = '' THEN '0' ELSE SUM(`S`.`Bad`) END AS Bd, CASE WHEN COALESCE( SUM(`S`.`Good` - `S`.`Bad`), '') = '' THEN '0' ELSE SUM(`S`.`Good` - `S`.`Bad`) END AS Point FROM `u_account` AS `C` LEFT JOIN `score_system` AS `S` ON `C`.`Id` = `S`.`Child Id` AND (SELECT Start FROM event_schedule WHERE CURDATE() >= Start AND End >= CURDATE()) < `S`.`Date` AND (SELECT End FROM event_schedule WHERE CURDATE() >= Start AND End >= CURDATE()) > `S`.`Date` GROUP BY `C`.`Id` ) AS `Table` ORDER BY Point DESC, Fname ASC I cant seem to pull the users rank from this and its donig my head in I've tried different things and they all dont work this is perhaps as close as I've got to figuring it out. This is the part that creates the users rank now its saying the Subquery returns more than 1 row but I just cant seem to think of away to implement this into my query above so that it displays the rank for each user. Code: [Select] (SELECT COUNT(*) + 1 FROM (SELECT U.Id, T.`User Id` FROM `u_account` U LEFT JOIN `score_system` T ON `T`.`User Id` = `U`.`Id`) x WHERE Table.Point >= (SELECT SUM(Good - Bad) FROM `score_system` GROUP BY `User Id`) ) AS RANK I'm also looking for this to display the same rank for both users with the same points so If bill and ben have 200points then they would both have the same rank but if bill was to have 201points then he would be higher up than ben. So can anyone lend me a hand. Thanks in advance I have a txt file of numbers e.g. 1,4,3,5,19,3,11 all in a column. Is it possible to echo only the highest 3 numbers? Hey, I've been working on a script to match playing card hands in a poker game against the river to return what the hand the user has and who won against other players. The problem is how do i approach an algorithm to do this in the first place. Cards are stored and structured by 2 characters seperated by a full stop. Example - 2 of diamonds and 3 of clubs is: D.2,C.3 now imagine a line of 5 cards (the river) and im trying to work out what they have and return the answer such as: 2 pairs or royal flush etc I so far decided my easiest way is to explode on the comma to get each card - then explode a second time on the full stop to get the suit and value into different variables. How ever - after that point im lost how i can do this up against the river to check what hand the user has. Any one got any tips on the best approach ? |