dshevnock Posted June 21, 2007 Share Posted June 21, 2007 This is the first time I have had to work with numbers that extend past 16 digits long. Here is the background behind this script: a user/admin manually types in the START NUMBER of a range of card numbers. Then the user/admin types in the END NUMBER of that set of card numbers. Then the form is submitted. After I run all of my checks to make sure the form variables are posted, they are numbers, 19 digits long, etc, I need to loop through the start to the end of the range entered. This is what I came up with (assuming startRange is 1111111111111111111 and endRange is 111111111111111113): // start the beginning of the sql statement that will be used to insert the card number range into the DB // this is so we can insert multiple rows with just one query $tempSQL = "INSERT INTO user_cards (card_number, active, sponsor_id, created_date, last_updated_date) VALUES"; // get the difference between the END RANGE and the START RANGE so we can use this as the conditional statement in the foor loop $bcDiff = bcsub($endRange, $startRange, 0); // start for loop // $i set to zero because we need to start off adding 0 to the very first startRange var for($i=0; $i <= $bcDiff; $i++){ $tempCardNumber = bcadd($startRange, $i, 0); // append this onto the end of the $tempSQL string so we can insert multiple rows with just one query $tempSQL .= " ('$tempCardNumber', 'N', '$tempSponsor', NOW(), NOW()),"; } // strip the last comma from the end of the $tempSQL string $tempSQL = substr($tempSQL, 0, -1); Is this clean, practical and safe programming? Any constructive criticism? Quote Link to comment https://forums.phpfreaks.com/topic/56605-please-critique-this/ Share on other sites More sharing options...
dshevnock Posted June 21, 2007 Author Share Posted June 21, 2007 bump... Quote Link to comment https://forums.phpfreaks.com/topic/56605-please-critique-this/#findComment-279588 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.