CEinNYC Posted December 9, 2010 Share Posted December 9, 2010 Hey all - What is the appropriate syntax to echo out each character name (vanity_name), and their total number of "ties" "wins" and "losses" Thanks for your help! $q1 = "SELECT Wins, Ties, Losses from game_char WHERE vanity_name='mario'"; $mario_sql = mysql_query($q1); <?php echo "Mario: " . $mario_sql; ?> [attachment deleted by admin] Quote Link to comment Share on other sites More sharing options...
Rifts Posted December 9, 2010 Share Posted December 9, 2010 $q1 = "SELECT Wins, Ties, Losses from game_char WHERE vanity_name='mario'"; while($row = mysql_fetch_assoc($q1)) { echo $row['wins']; } Quote Link to comment Share on other sites More sharing options...
BlueSkyIS Posted December 9, 2010 Share Posted December 9, 2010 ^ forgot to execute $q1 before using mysql_fetch_assoc() on the result... $q1 = "SELECT Wins, Ties, Losses from game_char WHERE vanity_name='mario'"; $result = mysql_query($q1) or die(mysql_error()); while($row = mysql_fetch_assoc($result)) { echo $row['wins']; } Quote Link to comment Share on other sites More sharing options...
CEinNYC Posted December 9, 2010 Author Share Posted December 9, 2010 Thanks!! Quote Link to comment Share on other sites More sharing options...
Rifts Posted December 9, 2010 Share Posted December 9, 2010 yeah my bad im use to doing it this way $q1 = mysql_query("SELECT Wins, Ties, Losses from game_char WHERE vanity_name='mario'"); while($row = mysql_fetch_assoc($q1)) { echo $row['wins']; } Quote Link to comment Share on other sites More sharing options...
CEinNYC Posted December 9, 2010 Author Share Posted December 9, 2010 If I wanted all the character names, and all wins, losses, and ties, would I repeat this for each character, or is there a more efficient way? Mario Wins: Ties: Losses: Link Wins: Ties: Losses: Quote Link to comment Share on other sites More sharing options...
Andy-H Posted December 9, 2010 Share Posted December 9, 2010 $query = "SELECT vanity_name, Wins, Ties, Losses FROM game_char ORDER BY Wins DESC"; $result = mysql_query($query)or trigger_error("MySQL: " . mysql_error()); while($row = mysql_fetch_row($result)) { echo <<<STATS <pre> <span style="font-weight:bold;">$row[0]</span> Wins: $row[1] Ties: $row[2] Losses: $row[3] </pre> STATS; } Quote Link to comment Share on other sites More sharing options...
CEinNYC Posted December 9, 2010 Author Share Posted December 9, 2010 Thank you! 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.