Jump to content


Photo

Three digit variable.


  • Please log in to reply
3 replies to this topic

#1 anabelle

anabelle
  • New Members
  • Pip
  • Newbie
  • 2 posts

Posted 28 October 2006 - 06:37 PM

Hi, im using a really simple script in www.gathacol.net/cenefa/ver.php?id=001 to generate the links in the arrows, im using

<? echo($id+1) ?>

but it generates a single digit variable.. and i need always 3 digit so that the id works.

How can i do to make the links to a three digit id?

#2 kenrbnsn

kenrbnsn
  • Staff Alumni
  • Advanced Member
  • 8,235 posts
  • LocationHillsborough, NJ, USA

Posted 28 October 2006 - 06:58 PM

Use sprintf()

<?php
echo sprintf("%03d",$id);
?>

Ken

#3 Psycho

Psycho
  • Moderators
  • Move along, nothing to see here
  • 11,892 posts
  • LocationCanada

Posted 28 October 2006 - 07:04 PM

Assuming you want leading 0's:

$linkID = "00".($id+1);
$linkID = substr($linkID,strlen($linkID)-3,3)
echo $linkID;

EDIT: Nevermind, I like his solution better.
The quality of the responses received is directly proportional to the quality of the question asked.

I do not always test the code I provide, so there may be some syntax errors. In 99% of all cases I found the solution to your problem here: http://www.php.net

#4 anabelle

anabelle
  • New Members
  • Pip
  • Newbie
  • 2 posts

Posted 28 October 2006 - 07:19 PM

thanks ;) im using sprintf

it works great!




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users