The importance of padding and using int with php and strings

programming with the MySQL environment and PHP or other server side languages.
Post Reply
darknkreepy3#
Site Admin
Posts: 247
Joined: Tue Oct 27, 2009 9:33 pm

The importance of padding and using int with php and strings

Post by darknkreepy3# »

If you have ever auto_increment=true your table columns, you should know this:

1. auto_increment indexes
columns that auto_increment begin with 1, not 0 like Arrays and other computer counting items do.
the first zero (0) array point holds the current index of your column's length.
sometimes it needs to be reset and all items need to be re-evaluated for proper auto_increment listing

2. php, nor many script languages, do not see string("01") and integer(1) as the same thing.
some intelligent scripting languages try to guess at what you want, but normally you will want to convert strings to integers when doing calculations.

a good way in php ~ mysql to renumerate a troublesome column...

-----
$server='localhost';
$user='yourusername';
$pass='passwordhere';
$connect=mysql_connect($server,$user,$pass)or die("Error, login to $server failed. <span class='error'>".mysql_error()."</span>");
$selDB=mysql_select_db($db)or die("Could not select database $db: <span class='error'>".mysql_error()."</span>");
$query="SELECT * FROM $tableName";
$linkID=mysql_query($query)or die(mysql_error());
$lenID=mysql_num_rows($linkID);
//
for($a=0;$a<$lenID;$a++)
{
$rowID=mysql_fetch_assoc($linkID);
$queryID="UPDATE $tableName SET id='".$a."' WHERE id='".$rowID['id']."'";
mysql_query($queryID)or die(mysql_error());
}
mysql_close($connect);
-----
Post Reply