Ravens PHP Scripts: Forums
 

 

View next topic
View previous topic
Post new topic   Reply to topic    Ravens PHP Scripts And Web Hosting Forum Index -> PHP
Author Message
warren-the-ape
Worker
Worker



Joined: Nov 19, 2007
Posts: 196
Location: Netherlands

PostPosted: Sat Jun 14, 2008 10:09 am Reply with quote

Hopefully the right section, if not please move Smile

I created a new module with a table in it. This table has a couple of rows and is filled using a couple of variables.

I searched around but havent found anything useful.

How can i auto-number all these rows using a variable or something?


example;
01 - row 1
02 - row 2
03 - row 3
etc..

01, 02.. would need to be displayed in front of every row (and fill a <td>).
Just like the online members in the 'Site/User Info' box really.

Not sure if this is a very very simple thing to do but my php knowledge is still pretty limited, so dont laugh Laughing
 
View user's profile Send private message
montego
Site Admin



Joined: Aug 29, 2004
Posts: 9457
Location: Arizona

PostPosted: Sat Jun 14, 2008 1:14 pm Reply with quote

It is actually as simple as within your MySQL table defining an integer field and tell it to be "auto-increment". Take a look a just about any nuke table and you will see that the first field is set up in this manner.

When you go to insert a record in the table, you just provide either NULL or '' as the value for that field and MySQL will take care of creating the next sequence in line.

_________________
Where Do YOU Stand?
HTML Newsletter::ShortLinks::Mailer::Downloads and more... 
View user's profile Send private message Visit poster's website
warren-the-ape







PostPosted: Sat Jun 14, 2008 1:38 pm Reply with quote

Thnx for the reply Montego, but i dont want to use MySQL for it.
The data isnt coming from a database anyway so it would be kinda useless.

I thought it would be very simple to make some function for a variable or something just with PHP?

Otherwise i think ill have to search for a javascript solution.
 
montego







PostPosted: Sat Jun 14, 2008 2:38 pm Reply with quote

Too funny, I completely missed what it was you were trying to do. Sorry about that. Embarassed

I just keep incrementing a variable by one and echo it out in its own <td></td> set of tags. I guess I don't understand what you mean by "auto-increment"....

For example,
At the start I could set some variable like this:

$i = 1;

Then, inside my loop:

Some loop {
statement;
statement;
echo '<td>' . $i . '</td>';
statement;
statement;
$i++;
}

At each iteration through the loop $i is incremented by one...

Am I still missing what it is that you are trying to do?
 
warren-the-ape







PostPosted: Sat Jun 14, 2008 3:29 pm Reply with quote

Aaaaah yes, thats it! :clap:

You pointed me in the right direction Wink

I now have;

Code:
$i = 1;


if ($i < 10) {
    $nmbr = "0$i.";
} else {
    $nmbr = "$i.";
}
$i++;


with the $nmbr in my <td> and its working like a charm.

I cooked up the other stuff by looking at the code for the standard 'user info' block for nuke Razz


Last edited by warren-the-ape on Sun Jun 15, 2008 9:43 am; edited 1 time in total 
montego







PostPosted: Sun Jun 15, 2008 7:05 am Reply with quote

Cool! Very good.
 
Display posts from previous:       
Post new topic   Reply to topic    Ravens PHP Scripts And Web Hosting Forum Index -> PHP

View next topic
View previous topic
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You can attach files in this forum
You can download files in this forum


Powered by phpBB © 2001-2007 phpBB Group
All times are GMT - 6 Hours
 
Forums ©