Greaser9780 Posted February 16, 2007 Share Posted February 16, 2007 I posted this ? in mysql but no one has really been there for hours.Just wondering if anyone over here would have some insight. I decided to put rank in my game table.For the life of me I cannot figure out how to update and set the rank. I have the table already set up to display the clan name ordered by wins descending. Then everytime a gamer reports the loss I can automatically run the update in my php file when the losses and wins are reported. UPDATE `game` SET `rank`='?' ORDER BY ASC Can't fill in that ? Quote Link to comment Share on other sites More sharing options...
Jessica Posted February 16, 2007 Share Posted February 16, 2007 you can't update with an order. Explain what you're trying to do. You want to order them and then increment the order or something? I think you'd have to do this in PHP with many queries. Quote Link to comment Share on other sites More sharing options...
dual_alliance Posted February 16, 2007 Share Posted February 16, 2007 If you had that, wouldnt you be better to run a CRON that checks to see whether the player has lost or won? Quote Link to comment Share on other sites More sharing options...
Greaser9780 Posted February 16, 2007 Author Share Posted February 16, 2007 I already figured out how to report a loss/win. query the db and display the number of wins/losses for each clan. I list that all on a table for each game. I am trying to set up a way to rank each clan by number of wins. Then display Rank,Clan Name, Wins, Losses, and Clan Id in my table for that game. I don't know what CRON is? Quote Link to comment Share on other sites More sharing options...
Greaser9780 Posted February 16, 2007 Author Share Posted February 16, 2007 Would probably be alot easier to just set numbers down the left hand side of my table 1-25 and then list the first 25 clans of my query. On the other hand if a game only has 5 clans at the moment I don't want to have to change the page everytime someone creates a new clan. Quote Link to comment Share on other sites More sharing options...
Jessica Posted February 16, 2007 Share Posted February 16, 2007 You don't need to store another field for rank if it's just based off wins - just rank them in PHP when you select them, order them by wins. Quote Link to comment Share on other sites More sharing options...
Greaser9780 Posted February 16, 2007 Author Share Posted February 16, 2007 Done that already. I am trying to display to my users what place each clan is in. How do I place a seven next to the clan in 7th place and so on. Here's how I set up the table so far. I have one of thes queries for each item (clan name, wins, losses, id): <?PHP $sql="SELECT `clan_name`,`wins`,`losses`,`message`,`clan_id`,`link`,`last_battle` FROM `table` ORDER BY `wins` DESC"; $res=mysql_query($sql) or die(mysqll_error()); while ($row = mysql_fetch_array($res)) { $list = "<table width='20%'>"; $list .= "<td>"; $list .= "<td >".$row["clan_name"]."</td>"; $list .= "<td>"; $list .= "</table>"; echo( $list ); } ?> Quote Link to comment Share on other sites More sharing options...
Greaser9780 Posted February 16, 2007 Author Share Posted February 16, 2007 What if I used mysql_num_rows to get the number of clans then start with #1 and increment it to the last row? Quote Link to comment Share on other sites More sharing options...
Jessica Posted February 16, 2007 Share Posted February 16, 2007 when you loop through them you just add to a number. Your table is also kind of weird - you had no rows and many open cells. <?PHP $sql="SELECT `clan_name`,`wins`,`losses`,`message`,`clan_id`,`link`,`last_battle` FROM `table` ORDER BY `wins` DESC"; $res=mysql_query($sql) or die(mysqll_error()); $rank = 1; print '<table>'; while ($row = mysql_fetch_array($res)){ print "<tr><td>Rank: $rank</td><td >".$row["clan_name"]."</td></tr>"; $rank++; } print '</table>'; ?> Quote Link to comment Share on other sites More sharing options...
Greaser9780 Posted February 16, 2007 Author Share Posted February 16, 2007 TY jesirose. I figured it would surround $rank=1, but I didn't know that putting 1+1 would make it increment while printing a table from a query. I never would of tried it in a million years. I am going to be creating a lot of these types of tables for my site. Is there anywhere here where I can find more info on them. Next Task is to find out how to display winning or losing streak. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.