Jump to content


Photo
- - - - -

Numbered Mysql results!


  • Please log in to reply
5 replies to this topic

#1 influct

influct

    Young Padawan

  • Members
  • Pip
  • 63 posts

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!

#2 influct

influct

    Young Padawan

  • Members
  • Pip
  • 63 posts

Posted 30 September 2006 - 09:28 AM

Yeh I know:P
But its usefull.

#3 Indigo

Indigo

    Official Alien

  • Members
  • PipPipPip
  • 617 posts
  • 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.


#4 Hayden

Hayden

    P2L Jedi

  • Members
  • PipPipPip
  • 717 posts
  • 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

#5 Matthew.

Matthew.

    Official Spammer .Matt

  • Members
  • PipPipPipPip
  • 2,749 posts
  • 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 ;)

#6 Hayden

Hayden

    P2L Jedi

  • Members
  • PipPipPip
  • 717 posts
  • 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 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users