Jump to content


Photo

how to count and display records?


  • Please log in to reply
2 replies to this topic

#1 New4You

New4You
  • New Members
  • Pip
  • Newbie
  • 2 posts

Posted 22 May 2006 - 01:26 PM

Hi there all,

Maybe its really simple, and Im gunna look stupid, but here goes anyway .... [img src=\"style_emoticons/[#EMO_DIR#]/wink.gif\" style=\"vertical-align:middle\" emoid=\":wink:\" border=\"0\" alt=\"wink.gif\" /]

I have a recorset that Im returning on my php page. I have a download site - it contains a 'Top 100 Downloads' page. This page lists all the top 100 records. I've got that part to work ok ...

But what I really want to do, is for each record displayed, also display a record number.

eg.

1. Download file A
2. Download file B
3. Download file C
4. Download file D
etc ...

Can someone please offer some help ?

Thanks all ! [img src=\"style_emoticons/[#EMO_DIR#]/smile.gif\" style=\"vertical-align:middle\" emoid=\":smile:\" border=\"0\" alt=\"smile.gif\" /]

Jay



#2 obsidian

obsidian
  • Staff Alumni
  • Advanced Member
  • 3,202 posts
  • LocationSeattle, WA

Posted 22 May 2006 - 01:59 PM

well, if you've already got it displaying the records, just set up an incrementer within the loop where you echo your results... something like this should work nicely:
$res = mysql_query($query); // whatever you're selecting
$count = 0;
while ($row = mysql_fetch_array($res)) {
  ++$count;
  echo "$count. $row['name']<br />\n";
}

notice that with each loop, $count is being incremented to reflect the row number. that's really all you need.
You can't win, you can't lose, you can't break even... you can't even get out of the game.

<?php
while (count($life->getQuestions()) > 0)
{   $life->study(); } ?>
  LINKS: PHP: Manual MySQL: Manual PostgreSQL: Manual (X)HTML: Validate It! CSS: A List Apart | IE bug fixes | Zen Garden | Validate It! JavaScript: Reference Cards RegEx: Everything RegEx

#3 New4You

New4You
  • New Members
  • Pip
  • Newbie
  • 2 posts

Posted 23 May 2006 - 01:29 AM

thanks obsidian

Two thumbs up to you mate ! [img src=\"style_emoticons/[#EMO_DIR#]/laugh.gif\" style=\"vertical-align:middle\" emoid=\":laugh:\" border=\"0\" alt=\"laugh.gif\" /]

I knew it would not be difficult for someone in the know such as yourself!

Thanks again - I'm looking forward to implementing into my site asap!!!

Cheers
Jamie




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users