Jump to content

auto increase?


whare

Recommended Posts

Hi all


right first things first Im new to php so please explain thens so i can understand them lol

right here is what i want to do I want to do a number increase with a prefix so i could have DAV0001 and then for the next one DAV0002 all the way to DAV9999 but i also would like it to use the the nembers that are not in use dew to removed accounts so EG:

DAV0001 [INUSE]
DAV0002 [INUSE]
DAV0003 [DELETED]
DAV0004 [INUSE]
DAV0005 [INUSE]
DAV0006 [NOTUSED]

so with that it will go back and use 0003 again befor using 0006

now i would like them to be formated like that on the webpage along with other info that i am working on now but im just stuck on that

oohhh by the way I am using mySQL db just to help you help me with this

Thanx All
Whare

Link to comment
Share on other sites

Well the easiest thing to do would be to create a column in your database that has the AUTO_INCREMENT attribute, where it will start at 1 and then add 1 to the highest of that column in the table, however, it will not do what you want to do in terms of rewriting deleted ones... so it would go like this

1, 2, 3, 4, 5, 6
then when you delete, say 3, you'd have
1,2,4,5,6
then when you add another,
1,2,4,5,6,7

But that's all I can think of. Maybe someone else has a better idea.
Link to comment
Share on other sites

I'm still a bit of a new guy myself, but you could try checking the number using strlen (even though its a number, php should be able to look at it as a string), if its 1, then append 3 zeroes to the front, if 2, append 2 zeroes. There's probably a better way of doing this, but this should work also.. so

[code]<?php

//Add the appropriate number of zeroes
switch(strlen($num)) {
  case 1:
      $num .= "000".$num;
      break;
  case 2:
      $num .="00".$num;
      break;
  case 3:
      $num .="0".$num;
  case 4:
      break;
}

//Append the number now to the username
$username .= $num;

?>[/code]


Again someone might have a much cleaner, better way of doing this.
Link to comment
Share on other sites

Great thanx

I will have a look and give it a go see if i can get it to work :) although I think i should have played with an easyer script as I have only been working with php for 3 days lol but never mind its not that hard if you can understand the basics and its even easyer with places like this that have users who will help

Thanx Alot
Whare
Link to comment
Share on other sites

right peoject update and im still stuck lol

here look

[code]<?php
include "db.php";

// Get all the data from the "example" table
$result = mysql_query("SELECT * FROM users")
or die(mysql_error()); 

echo "<table border='1'>";
echo "<tr> <th>Name</th> <th>Pilot ID</th> <th>Join Date</th> </tr>";
// keeps getting the next row until there are no more to get
while($row = mysql_fetch_array( $result )) {
// Print out the contents of each row into a table
echo "<tr><td>";
echo $row['first_name'];
echo "&nbsp;";
echo $row['last_name'];
echo "</td><td>";
echo $row['userid'];
echo "</td><td>";
echo $row['signup_date'];
echo "</td></tr>";
}

echo "</table>";
?>[/code]

Where echo $row['userid']; that is what i want to change to DAVxxx[userid] but the number of "0" depends on the userid  so if the userid is 1 there will be 3 "0" but if it is 21 there will only be 2 "0" added now i tried to add the code the bpops said about but i have no idea what im doing lol here is bpops code

[code]<?php

//Add the appropriate number of zeroes
switch(strlen($num)) {
  case 1:
      $num .= "000".$num;
      break;
  case 2:
      $num .="00".$num;
      break;
  case 3:
      $num .="0".$num;
  case 4:
      break;
}

//Append the number now to the username
$username .= $num;

?>[/code]

thanx all
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.