Re: Problem with inserting numbers...

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 




On Aug 10, 2011, at 8:22 PM, Jason Pruim wrote:

So here I am attempting to generate some numbers to be inserted into a database... eventually they will make up a phone number (Which I've emailed about before and know about the bad ideas with it.. But it's the customer :))

Here is the code I am working with:

<?PHP
function number_pad($number,$n) {
return str_pad((int) $number,$n,"0",STR_PAD_LEFT);
}

$SQL = "SELECT * FROM Test WHERE `areacode` = '907' AND `prefix` = '200' LIMIT 5";

$result = mysql_query($SQL);
//$num = "0000";
//foreach ($result as $key => $value) {
//    echo $key . "-" . $value . "-" . number_pad($num, "4") . "<BR>";
//    $num++;
//}

while ($num != "10000") {

Problem is here ^ You are testing a numeric $num with a string "10000", which $num will *never* equal. Leave off the quotes on the number.

   while($row = mysql_fetch_assoc($result)) {
       $padnum = number_pad($num, "4");
echo $row['areacode'] . "-" . $row['prefix'] . "-" . $padnum . "<BR>";
       $num++;
   }


}

?>

basically all I'm trying to do is generate the last 4 digits starting at 0000 and going up to 9999. for testing purposes I'm just echoing back but will eventually insert the complete number back into the database as a 7 digit string.

The error I'm getting is:

Fatal error: Maximum execution time of 30 seconds exceeded in /home/ pruimpho/public_html/jason/dev/clients/flewid/Phone/config/ phoneareacodes.php on line25

which is where the second while starts...

Does anyone know a better way to do this?

I'm off to finish searching google while waiting for some good news :)

Thanks Everyone!


Jason Pruim
pruimj@xxxxxxxxx




--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux