Allow unlimited amount with php

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
nite4000
Forum Contributor
Posts: 209
Joined: Sun Apr 12, 2009 11:31 am

Allow unlimited amount with php

Post by nite4000 »

Here is a problem I currently have and would like to find a solution

I have a script and when they create a package they can enter amin amount and max amount now what I wanna do is fine a way to allow an umlimited max amount. but have it read off the db field at the same time.

if anyone has any solutions please let me know
genix2011
Forum Commoner
Posts: 74
Joined: Tue Aug 02, 2011 4:00 pm

Re: Allow unlimited amount with php

Post by genix2011 »

Hi,

not possible, you can just use the biggest numeric datatype in MySQl, the BIGINT, which allows numbers from -9223372036854775808 to 9223372036854775807.

Even if there was a way to get more than that (LONGBLOB, LONGTEXT), unlimited is just impossible, because you have only limited space.

LONGTEXT can save 0-4294967295 chars
LONGBLOB can save 0-4294967295 bytes

So you'll have to set a limit somewhere.
Greets.
nite4000
Forum Contributor
Posts: 209
Joined: Sun Apr 12, 2009 11:31 am

Re: Allow unlimited amount with php

Post by nite4000 »

strange becuz i know on goldcoders script they have unlimited option but i am not sure how they do the database i guess its worth checking into to see if i can mimic thanks for the reply
User avatar
twinedev
Forum Regular
Posts: 984
Joined: Tue Sep 28, 2010 11:41 am
Location: Columbus, Ohio

Re: Allow unlimited amount with php

Post by twinedev »

Well, depends on how you are wanting to read from the database, are you reading in the packages and then comparing data to the package, or do you have a package, and you trying to find data in the database that fits within the package?

Basically what I would would be set it so a maximum of -1 = unlimited (assuming you do not need negative values).

Then, if you are comparing something entered to the package, use:

Code: Select all

$aryPlan = mysql_fetch_assoc($rsPlans); // Or whatever to you use to get plans from DB

if ($intUserValue >= $aryPlan['MinValue'] && ($aryPlan['MaxValue'] == -1 || $intUserValue <= $aryPlan['MaxValue'])) {
    echo "You are withing parameters, sir!\n";
}
else {
    echo "You are out of scope... Try again!\n";
}
But if you have a values for the min/max of a plan, and are wanting to search for matching records that fit within that plan:

Code: Select all

$intPlanMin = 50; // Set to the plan's minimum
$intPlanMax = 500; // Set to plan's maximum, which would be -1 if there is no maximum

$SQL = 'SELECT * FROM tblAccounts WHERE (PlanValue >= ' . $intPlanMin;
if ($intPlanMax > -1) {
	$SQL .= ' AND PlanValue <= ' . $intPlanMax; 
}
$SQL .= ') AND OtherConditions = "go here"  ORDER BY PlanID ';

$rsAccounts = mysql_query($SQL);
if ($rsAccounts && mysql_num_rows($rsAccounts) > 0) {
	while ($aryAccount = mysql_fetch_assoc($rsAccounts)) {
		// Do something with this row which is in $aryAccount
	}
	mysql_free_result($rsAccounts);
}
unset ($rsAccounts);
And lastly, if you have a users value, and you are wanting to find plans that this value fits within:

Code: Select all

$intUserValue = 45; // Actual user value, 0 - whatever

$SQL = 'SELECT * FROM tblPlans WHERE MinValue <= ' . $intUserValue . ' AND (MaxValue = -1 OR MaxValue >= '.$intUserValue .')';

$rsPlans = mysql_query($SQL);
if ($rsPlans && mysql_num_rows($rsPlans)>0) {
	while ($aryPlan = mysql_fetch_assoc($rsPlans)) {
		// Do something with this row which is in $aryPlan
	}
	mysql_free_result($rsPlans);
}
unset ($rsPlans);
Post Reply