HOw do I get PHP/MySQL output in a table to be numbered?
-
have a MySQL DB that has a DB w/ one table, that having two rows. I use this PHP to retrieve it and put it into a table (It's for hi-scores): $fetch = mysql_query("SELECT * FROM scores ORDER BY score DESC LIMIT 10"); while($row = mysql_fetch_array($fetch)) { echo "<table border='1' width=300><tr><td>  $row[name]  </td><td>  $row[score]  </td></tr></table>"; } I would like to have each horizontal row have a number before it, numbered 1 - 10 (it's a hi-score platform). How would I do that? Keep in mind that I don't want them numbered as they are in the DB, but as they are sorted and listed on the page. Help? The page is here: http://pennyontherail.com/score10.php . Thank you very much!
-
Answer:
First thing, it's not a good idea to do SELECT *, just select the fields that you want, even if * is all of them. Why? Because it causes strain on the db engine. Another thing, you do not need to create a table for each iteration. Just one table, then loop through the rows. To make your numbers, you will want to add a number to the loop, eg: <table> <thead> <tr> <th>Number</th><th>Person</th><th>Scor… </tr> </thead> <tbody> <?php while($row = mysql_fetch_array($fetch)) { $i = $i+1 $name = $row[0]; $score = $row[1]; ?> <tr> <td><?php echo $i; ?></td><td><?php echo $name; ?></td><td><?php echo $score; ?></td> </tr> <?php } mysql_free_result($fetch); ?> </tbody> </table>
m3thus3l... at Yahoo! Answers Visit the source
Other answers
Just make a counter. Pseudocode i = 1 echo table foreach row echo i echo field name i++ end foreach echo /table
LordSam
Related Q & A:
- How do I get on to chat with a real Yahoo tech?Best solution by Yahoo! Answers
- How can I get an overseas job as a civil engineer?Best solution by jobs.monster.com
- How can I get tickets for the serie a Torino-Juventus derby?Best solution by Yahoo! Answers
- How can I get my regular avatar of a real picture back as my avatar instead of the one now?Best solution by Yahoo! Answers
- How do I get into safe mode without a keyboard?Best solution by pistonheads.com
Just Added Q & A:
- How many active mobile subscribers are there in China?Best solution by Quora
- How to find the right vacation?Best solution by bookit.com
- How To Make Your Own Primer?Best solution by thekrazycouponlady.com
- How do you get the domain & range?Best solution by ChaCha
- How do you open pop up blockers?Best solution by Yahoo! Answers
For every problem there is a solution! Proved by Solucija.
-
Got an issue and looking for advice?
-
Ask Solucija to search every corner of the Web for help.
-
Get workable solutions and helpful tips in a moment.
Just ask Solucija about an issue you face and immediately get a list of ready solutions, answers and tips from other Internet users. We always provide the most suitable and complete answer to your question at the top, along with a few good alternatives below.