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] Link to comment https://forums.phpfreaks.com/topic/221156-echo-table-numbers/ 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']; } Link to comment https://forums.phpfreaks.com/topic/221156-echo-table-numbers/#findComment-1145117 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']; } Link to comment https://forums.phpfreaks.com/topic/221156-echo-table-numbers/#findComment-1145118 Share on other sites More sharing options...
CEinNYC Posted December 9, 2010 Author Share Posted December 9, 2010 Thanks!! Link to comment https://forums.phpfreaks.com/topic/221156-echo-table-numbers/#findComment-1145123 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']; } Link to comment https://forums.phpfreaks.com/topic/221156-echo-table-numbers/#findComment-1145124 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: Link to comment https://forums.phpfreaks.com/topic/221156-echo-table-numbers/#findComment-1145129 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; } Link to comment https://forums.phpfreaks.com/topic/221156-echo-table-numbers/#findComment-1145134 Share on other sites More sharing options...
CEinNYC Posted December 9, 2010 Author Share Posted December 9, 2010 Thank you! Link to comment https://forums.phpfreaks.com/topic/221156-echo-table-numbers/#findComment-1145139 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.