Wrox Programmer Forums
| Search | Today's Posts | Mark Forums Read
PHP Databases Using PHP in conjunction with databases. PHP questions not specific to databases should be directed to one of the other PHP forums.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the PHP Databases section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old July 21st, 2004, 02:04 PM
Authorized User
 
Join Date: Jun 2003
Location: , , .
Posts: 43
Thanks: 0
Thanked 0 Times in 0 Posts
Default drops 0(zero)

Hello to all,

I have a problem with my table in mysql... The student id field is an int which can only hold 9 digits but will not accept a 0 as the first digit of the sid. What can I do to have it display the 0.

Thank you for all your help.

dungey
 
Old July 22nd, 2004, 09:11 AM
Friend of Wrox
 
Join Date: Jun 2003
Location: , , United Kingdom.
Posts: 256
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Int fields won't store a leading zero in cases other than zero, since that's not what integer numbers are supposed to be. However, since the student id is never actually going to be the subject of any mathematical calculations, the fact that it is actually a number is surely coincidental. So, surely the easiest option would be to change the field type to varchar(9). When posting values from forms, you could protect leading zeros by force the variable recieving the posted value to accept it as a string, by casting it as such:

$student_id = (string)$_POST['student_id'];

Alternatively, if student_id is actually a zero-padded string containing a numeric value, it is probably better to use a preformatted string function such as printf.

Let us know how you get on.

Take it easy,
Dan
 
Old July 22nd, 2004, 10:41 AM
Authorized User
 
Join Date: Jun 2003
Location: , , .
Posts: 43
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Dan,

thanks a bunch, the field type change from int to varchar(9) is a great idea and make more pratical sense in this case.

Thank again...

dungey




Similar Threads
Thread Thread Starter Forum Replies Last Post
CDO email - character 1023 drops out! BananaJim Classic ASP Professional 1 January 10th, 2007 05:06 PM
Create Dynamic Form; end-user adds/drops columns pkaptein1 Access 6 February 15th, 2006 03:32 AM
ASP.NET loses / drops Session State information Quickdraw General .NET 0 February 8th, 2005 03:09 PM
ASP.NET loses / drops Session State information Quickdraw VS.NET 2002/2003 1 February 8th, 2005 03:08 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.