notnamed Posted February 14, 2007 Share Posted February 14, 2007 Hi, I'm trying to do exactly what's done in this thread: http://www.phpfreaks.com/forums/index.php/topic,89787.0.html And this thread: http://www.phpfreaks.com/forums/index.php/topic,102255.0.html However, I'm too much of a PHP/mySQL newbie to adapt this code to fit what I already have. Note that when I coded this there was a little bit of variable confusion... it says "rank" where it should say "points" in some things. Sorry. Hopefully this is enough relevant information. Thanks! <?php include("config.php"); // this is what connects to my database if(!isset($_REQUEST['id'])) { // the script selects a user based on an ID given in the URL, check for it echo("No id!"); } if(isset($_REQUEST)) { $requestedun = $_REQUEST['id']; $query="SELECT * FROM user_system WHERE username='$requestedun'"; // selects from the first table, which contains username and personal info $query_cats="SELECT * FROM cats WHERE username='$requestedun'"; // second table $result=mysql_query($query); $num=mysql_numrows($result); $result_cats=mysql_query($query_cats); $num_cats=mysql_numrows($result_cats); $i=0; // I have no idea what all that above that does, someone else coded it. while ($i < $num AND $i < $num_cats) { echo("Username: ".$requestedun."<br />"); $firstname=mysql_result($result,$i,"firstname"); $lastname=mysql_result($result,$i,"lastname"); $aimsn=mysql_result($result,$i,"aimsn"); $rank=mysql_result($result,$i,"rank"); $photos=mysql_result($result_cats,$i,"photos"); $webdesign=mysql_result($result_cats,$i,"webdesign"); $webgfx=mysql_result($result_cats,$i,"webgfx"); $randomstuff=mysql_result($result_cats,$i,"randomstuff"); // get all the information from both queries echo("Points: ".$rank."<br /> First name: ".$firstname."<br /> Last name: ".$lastname."<br /> AIM screen name: ".$aimsn." <br /><b>Categories</b><br />"); if(!$photos) { echo("Photos: No<br />"); } else { echo("Photos: Yes<br />"); } if(!$webdesign) { echo("Web Design: No<br />"); } else { echo("Web Design: Yes<br />"); } if(!$webgfx) { echo("Web Graphics: No<br />"); } else { echo("Web Graphics: Yes<br />"); } if(!$randomstuff) { echo("Random Stuff: No<br />"); } else { echo("Random Stuff: Yes<br />"); } $i++; } } ?> Link to comment https://forums.phpfreaks.com/topic/38398-assign-rank-to-points-value/ Share on other sites More sharing options...
trq Posted February 14, 2007 Share Posted February 14, 2007 Can you just explain exactly what you want to do in English, where your getting your data from and all? The example you have posted is trying to query from two different tables at once, making your question unclear. Link to comment https://forums.phpfreaks.com/topic/38398-assign-rank-to-points-value/#findComment-184153 Share on other sites More sharing options...
notnamed Posted February 14, 2007 Author Share Posted February 14, 2007 Yeah, sorry. I'm getting data from the row 'rank' on the table 'user_system.' I want to take that information (which is actually my points value, not the rank, sorry for that confusion) and assign a rank to it, like in the posts I liked to - user #1 has 8 points, user #2 has 2 points, user #3 has 4 points, so it would show "Ranks: user #1 first place, user #3 second place, user #2 third place." Link to comment https://forums.phpfreaks.com/topic/38398-assign-rank-to-points-value/#findComment-184157 Share on other sites More sharing options...
redarrow Posted February 14, 2007 Share Posted February 14, 2007 Use the example here what you saw and then alter to your requirments ok. <?php $rank = 1; $prev = 0; $count = 0; while ($row = mysql_fetch_assoc ($result)) { $username= $row['username']; $name= $row['name']; $totaal= $row['totaal']; if ($totaal==$prev) { ++$count; } else { $rank = ++$count; } echo "$rank $name $totaal<br />"; $prev = $totaal; }?> Link to comment https://forums.phpfreaks.com/topic/38398-assign-rank-to-points-value/#findComment-184164 Share on other sites More sharing options...
notnamed Posted February 14, 2007 Author Share Posted February 14, 2007 I'm sure that does exactly what I need it to do... I just need some help figuring out how to alter it to my requirements. When I paste that code in thusly, nothing changes in the script (nothing is outputted). I've tried messing with the $result variables and such to make sure it's grabbing from the right database, but I wasn't the one who coded most of the mySQL queries, so I don't really understand what's going on. Unfortunately, neither does the person who coded them... he used a tutorial. <snip> $i++; } <?php $rank = 1; $prev = 0; $count = 0; while ($row = mysql_fetch_assoc ($result)) { $username= $row['username']; $name= $row['name']; $totaal= $row['totaal']; if ($totaal==$prev) { ++$count; } else { $rank = ++$count; } echo "$rank $name $totaal<br />"; $prev = $totaal; } } ?> Link to comment https://forums.phpfreaks.com/topic/38398-assign-rank-to-points-value/#findComment-184172 Share on other sites More sharing options...
benjaminbeazy Posted February 14, 2007 Share Posted February 14, 2007 $query = "SELECT * from user_system ORDER BY rank DESC LIMIT 0, 10"; $result = mysql_query($query); $i = 0; while($row = mysql_fetch_object($result){ $i = $i + 1; $name = "$row->first_name $row->last_name"; $rank = $i; echo '#'.$rank.': '.$name<br>"; } Link to comment https://forums.phpfreaks.com/topic/38398-assign-rank-to-points-value/#findComment-184177 Share on other sites More sharing options...
notnamed Posted February 14, 2007 Author Share Posted February 14, 2007 Argh. This is all very frustrating. I'm sure both of the examples posted here would work perfectly if I could just get them to work. I guess it's just going to be trial and error to get them working. Thanks for your very quick assistance. AHA! I got it to work. I finally figured out what these code snippets were DOING, and was able to get it to do what I WANTED it to do. Thanks again! Link to comment https://forums.phpfreaks.com/topic/38398-assign-rank-to-points-value/#findComment-184205 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.