dezkit Posted July 13, 2008 Share Posted July 13, 2008 i have a table set up id | league | wins | losses | ties 1 | CAL-O | 2 | 2 | 0 2 | CEVO-A| 0 | 0 | 0 is it possible to echo the table as CAL-O: 2-2-0 CEVO-A: 0-0-0 if yes, can i get the code? Link to comment https://forums.phpfreaks.com/topic/114494-solved-php-database-echo/ Share on other sites More sharing options...
JasonLewis Posted July 13, 2008 Share Posted July 13, 2008 Course it's possible... <table border="0" width="100%" cellpadding="1" cellspacing="0"> <tr> <td>League</td> <td>Wins</td> <td>Losses</td> <td>Ties</td> </tr> <?php $query = mysql_query("SELECT * FROM `table`"); if(mysql_num_rows($query) == 0){ ?> <tr> <td colspan="4">There is no data.</td> </tr> <?php }else{ while($r = mysql_fetch_array($query)){ $league = $r['league']; $wins = $r['wins']; $losses = $r['losses']; $ties = $r['ties']; ?> <tr> <td><?php echo $league; ?></td> <td><?php echo $wins; ?></td> <td><?php echo $losses; ?></td> <td><?php echo $ties; ?></td> </tr> <?php } } ?> </table> Wrote that on the fly so it may have errors. Link to comment https://forums.phpfreaks.com/topic/114494-solved-php-database-echo/#findComment-588752 Share on other sites More sharing options...
dezkit Posted July 13, 2008 Author Share Posted July 13, 2008 hmm thats weird. it doesn't show the data oO edit: the "There is no data." doesn't show, and so doesn't the data. Link to comment https://forums.phpfreaks.com/topic/114494-solved-php-database-echo/#findComment-588755 Share on other sites More sharing options...
JasonLewis Posted July 13, 2008 Share Posted July 13, 2008 You didn't copy and paste did you? You should change it around to suit your needs. Link to comment https://forums.phpfreaks.com/topic/114494-solved-php-database-echo/#findComment-588757 Share on other sites More sharing options...
dezkit Posted July 13, 2008 Author Share Posted July 13, 2008 yeah, i changed the `table` part... Link to comment https://forums.phpfreaks.com/topic/114494-solved-php-database-echo/#findComment-588759 Share on other sites More sharing options...
dezkit Posted July 13, 2008 Author Share Posted July 13, 2008 what the... <?php $result = mysql_query("SELECT * FROM matches") or die(mysql_error()); echo "<table>"; echo "<tr> <th>League</th> <th>Wins</th> <th>Losses</th> <th>Ties</th></tr>"; while($row = mysql_fetch_array( $result )) { // Print out the contents of each row into a table echo "<tr><td>"; echo $row['league']; echo "</td><td>"; echo $row['wins']; echo "</td><td>"; echo $row['losses']; echo "</td><td>"; echo $row['ties']; echo "</td></tr>"; } echo "</table>"; ?> doesn't work too Link to comment https://forums.phpfreaks.com/topic/114494-solved-php-database-echo/#findComment-588761 Share on other sites More sharing options...
JasonLewis Posted July 13, 2008 Share Posted July 13, 2008 Haha. That's good. Well it should work, depending on how you've implemented it. Link to comment https://forums.phpfreaks.com/topic/114494-solved-php-database-echo/#findComment-588763 Share on other sites More sharing options...
dezkit Posted July 13, 2008 Author Share Posted July 13, 2008 Oh wow, im so stupid, i was using the wrong table name, LOL. topic solved thanks for the code! <3 Link to comment https://forums.phpfreaks.com/topic/114494-solved-php-database-echo/#findComment-588764 Share on other sites More sharing options...
JasonLewis Posted July 13, 2008 Share Posted July 13, 2008 Haha nice, no worries. Link to comment https://forums.phpfreaks.com/topic/114494-solved-php-database-echo/#findComment-588766 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.