Pixel2Life Forum: Numbered Mysql results! - PHP Tutorials - Pixel2Life Forum

Jump to content

  • You cannot start a new topic
  • You cannot reply to this topic

Numbered Mysql results! How to number your mysql results. Rate Topic -----

Array

#1 User is offline   influct 

  • Young Padawan
  • Pip
  • Group: Members
  • posts 63
  • Joined: 30-August 06

Posted 30 September 2006 - 09:14 AM

Put in your average query:

Normal query here:
$sql = mysql_query("SELECT * FROM table");
$sql2 = mysql_query($sql);

Heres our starting number (0)
$newno = 0;

Heres our while statement (0)
While ($row = MySQL_fetch_array($sql)){
Heres what happenens!
The $newno variable for the first but is set to 0, and in the statement below we add one to it, so the total is 1.
When it repeats however it only repeats whats in the while statement, so our new math is 1+1, then it repeats to 2+1 and so on and so on - basically increments of 1

$newno = $newno + 1;
   echo"
$newno [b][color=#FF0000]And we echo the the number and whatever mysql result.[/color][b]
";
}


I used this on this page http://www.sfegaming...arcade/beta.php
(sorry if that counts as a plug:p)
If you look, top online games are numbered and I used it for layout purposes as well!
Look at the newest games box, see those smaller icons? Yup:)
Thats set up like this
if ($newno == 3){
echo"<br />";
}
so if its the third icon it prints a <br />

Handy eh?:o
Hope this helped some people!
0

#2 User is offline   influct 

  • Young Padawan
  • Pip
  • Group: Members
  • posts 63
  • Joined: 30-August 06

Posted 30 September 2006 - 09:28 AM

Yeh I know:P
But its usefull.
0

#3 User is offline   Indigo 

  • Official Alien
  • PipPipPip
  • Group: Members
  • posts 617
  • Joined: 17-July 05
  • Gender:Male
  • Location:Trondheim, Norway
  • Interests:Computing in general, especially design and programming of all kinds.

Posted 08 October 2006 - 11:47 AM

Not that bad, guess it might be useful for some.
Just one thing:

$newno = $newno + 1;

can be changed into

$newno = $newno++;

Or could it be done in another way, just write

$newno++;

Oh well, I don't remember, too long since I've worked with php.

Edited by Indigo, 08 October 2006 - 11:48 AM.

0

#4 User is offline   Hayden 

  • P2L Jedi
  • PipPipPip
  • Group: Members
  • posts 717
  • Joined: 07-October 05
  • Gender:Male
  • Location:Texas

Posted 13 October 2006 - 12:21 AM

i always just have an 'id' field in all my tables that auto increments as information is entered :P
0

#5 User is offline   Matthew. 

  • Official Spammer .Matt
  • PipPipPipPip
  • Group: Members
  • posts 2,749
  • Joined: 13-May 06
  • Gender:Male
  • Location:England

Posted 13 October 2006 - 02:33 PM

i always just have an 'id' field in all my tables that auto increments as information is entered :yoda:


Consider how p2l's latest tutorials are displayed "1, 2, 3, 4...20". Those numbers are not the IDs of the tutorials, they are generated within the loop like this ;)
0

#6 User is offline   Hayden 

  • P2L Jedi
  • PipPipPip
  • Group: Members
  • posts 717
  • Joined: 07-October 05
  • Gender:Male
  • Location:Texas

Posted 14 October 2006 - 12:28 AM

i always just have an 'id' field in all my tables that auto increments as information is entered :huh:


Consider how p2l's latest tutorials are displayed "1, 2, 3, 4...20". Those numbers are not the IDs of the tutorials, they are generated within the loop like this :)


lol. oh yeah. okay. do it so that the numbers are sequential and don't skip around. :)
0

Share this topic:


  • You cannot start a new topic
  • You cannot reply to this topic

0 user(s) are reading this topic
members, guests, anonymous users