Re: Problem with inserting numbers...
| From: | Tamara Temple | Date: | Thu, 11 Aug 2011 11:08:56 +0000 |
| Subject: | Re: Problem with inserting numbers... | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-314490@lists.php.net to get a copy of this message | ||
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 WHEREProblem is here ^ You are testing a numeric $num with a string "10000", which $num will *never* equal. Leave off the quotes on the number.areacode= '907' ANDprefix= '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") {
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@gmail.com