Jump to content

Recommended Posts

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?

Link to comment
https://forums.phpfreaks.com/topic/56605-please-critique-this/
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.