Jump to content


Photo

Counting 1-?


  • Please log in to reply
7 replies to this topic

#1 komquat

komquat
  • Members
  • PipPipPip
  • Advanced Member
  • 130 posts
  • LocationHoughton, MI

Posted 28 February 2006 - 01:32 PM

It is a pretty simple thing, or at least I thought, but I can not remember how to get sequential numbers

Ex.

1 A
2 B
3 C
4 D

I think it is something like

count=($i = '1', $i++);

Help or direction on this would be great.

Thanks


#2 obsidian

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

Posted 28 February 2006 - 01:38 PM

are you just referring to for()?
<?php
for ($i = 1; $i <= 10; $i++)
  echo $i . "<br />\n";
?>

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 komquat

komquat
  • Members
  • PipPipPip
  • Advanced Member
  • 130 posts
  • LocationHoughton, MI

Posted 28 February 2006 - 01:53 PM

I have a table, and I want this to show who is ranked #1 thru rank # 19. I have it in a loop, so I would use it like this
<?php
for ($i = 1; $i <= 19; $i++)

//Loop is here
while(Somefunction Here) {
<td>$i</td><td>$player</td><td>$points</td>
}

?>

Would I need a ';' after the for() statement?


#4 kanikilu

kanikilu
  • Members
  • PipPip
  • Member
  • 29 posts
  • LocationDallas, TX

Posted 28 February 2006 - 04:29 PM

<?php
for ($i = 1; $i <= 19; $i++) {
  echo "<td>$i</td><td>$player</td><td>$points</td>";
}
?>


#5 komquat

komquat
  • Members
  • PipPipPip
  • Advanced Member
  • 130 posts
  • LocationHoughton, MI

Posted 28 February 2006 - 05:30 PM

[!--quoteo(post=350259:date=Feb 28 2006, 11:29 AM:name=kanikilu)--][div class=\'quotetop\']QUOTE(kanikilu @ Feb 28 2006, 11:29 AM) View Post[/div][div class=\'quotemain\'][!--quotec--]
<?php
for ($i = 1; $i <= 19; $i++) {
  echo "<td>$i</td><td>$player</td><td>$points</td>";
}
?>
[/quote]

How would I put count loop inside of the While loop?


#6 AndyB

AndyB
  • Staff Alumni
  • Advanced Member
  • 5,465 posts
  • LocationToronto

Posted 28 February 2006 - 05:50 PM

Wait a minute! Where does the information actually come from about player names and score (or whatever is used to rank them)? If it's from a database then you can construct a single query to retrieve the highest 19 scores, ordered by score .... Bit more information please, then we'll figure out what this has to do with a while loop, or a for loop, or a counter.
Legend has it that reading the manual never killed anyone.
My site

#7 komquat

komquat
  • Members
  • PipPipPip
  • Advanced Member
  • 130 posts
  • LocationHoughton, MI

Posted 28 February 2006 - 06:05 PM

[!--quoteo(post=350299:date=Feb 28 2006, 12:50 PM:name=AndyB)--][div class=\'quotetop\']QUOTE(AndyB @ Feb 28 2006, 12:50 PM) View Post[/div][div class=\'quotemain\'][!--quotec--]
Wait a minute! Where does the information actually come from about player names and score (or whatever is used to rank them)? If it's from a database then you can construct a single query to retrieve the highest 19 scores, ordered by score .... Bit more information please, then we'll figure out what this has to do with a while loop, or a for loop, or a counter.
[/quote]

I am getting it from a DB, and I currently do that, but I want a rank for each one as well as the order.

I have:

Andy 10
Bob 12
Tony 14
John 22

I want them to have a rank in front of them.

#8 komquat

komquat
  • Members
  • PipPipPip
  • Advanced Member
  • 130 posts
  • LocationHoughton, MI

Posted 28 February 2006 - 10:04 PM

I figured it out.

thanks




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users