Tracking Forums, Newsgroups, Maling Lists
Home Scripts Tutorials Tracker Forums
 
  HOME    TRACKER    PHP




Finding Sums Of Two Numbers Under Maximum Value


I have two, or more, numbers and a maximum value. I need to find a way to calculate all unique combinations of those numbers whose sum is less than or equal to the maximum value.

For example:

First Number: 6
Second Number: 8
Maximum value: 30

Possible sums:
6, 12, 14, 16, 18, 20, 22, 24, 28, 30
(how I calculated those sums is listed at the end of the message)

If anyone could give me some suggestions that would be fantastic.

peer

// Calculated Sums
6 * 1 = 6
6 * 2 = 12
6 * 3 = 18
6 * 4 = 24
6 * 5 = 30

8 * 1 = 8
8 * 2 = 16
8 * 3 = 24;

6+8=14
6+16=22
12+8=20
12+16=28
18+8=26




View Complete Forum Thread with Replies

See Related Forum Messages: Follow the Links Below to View Complete Thread
Finding Out A Winner From Numbers
I have a little script that finds out a winner and a loser between 2 people:

$player1 = 'bob;
$player2 = 'dave';
$p1_points = '7';
$p2_points = '9';

if($p1_points > $p2_points) {
$winner = $player1;
$loser = $player2;
} elseif($p1_points < $p2_points) {
$winner = $player2;
$loser = $player1;
}
echo "1st = $winner and 2nd = $loser;
Quote1st = dave and 2nd = bob

So very simple. However, if I have 6 players, ($p1_points, $p2_points, $p3_points, $p4_points, $p5_points and $p6_points), how would I find out, not only a winner but in order of, 1st/2nd/3rd/4th and 5th place? Would it be some sort of array?

Finding Number In A String Of Numbers
I have a string of numbers separated by comma ',', eg
$str = "1, 3, 56, 8, 9, "; (there's a comma at the end, because it was easier for me to do so)

I need to compare a number ($id) if it's in the string. At first I thought, that strpos() will do the trick, but then it struck me, that 6 will be found (because of 56, ).

Sums, Averages Stuff Help
I need to do some sistem in PHP and MySQL, I have do it a
part but the other is the problem, basically is mathemetical
operations, te user register something and after insert some registry
and after is needed obtain sums, averages and something similar, does
anyone have some code similar for read about??...

SUMS And GROUP Tutorial
I'm looking for a tutorial on how to use SUMS and GROUPS to display data from an SQL database. I've had a quick look round but can't find the basics! I'm already familiar with displaying the data as it is but not performing calculations. Could someone point me in the right direction.

Adding Sums Of Array Values
I have two arrays:
('a'=>1,'b'=>3,'c'=>2,'d'=>6)
('a'=>2,'b'=>0,'c'=>4)

I need a very efficient function to add the values together for each element. For instance, the output would be an array:

('a'=>3,'b'=>3,'c'=>6,'d'=>6)

This function could potentially be used in billions of iterations, so it needs to be as efficient as possible.

Change Straight Numbers Into Phone Numbers?
How can I change these two numbers into phone numbers?

5551231234
9009876789

echo INTO:

(555) 123-1234
(900) 987-6789

Removing Numbers From A Set Of Numbers
Say theres a limit of number choices from 1 to 10. (not including 0)

Now these numbers are buyable so say some one buys number 7.

With a query or what ever is needed i need to find a way for the screen to then display:

1 2 3 4 5 6 8 9 10.

As you notice 7 is not missing.. but it could be any number and more than one number that has already been taken... How can this be done in PHP and MYSQL or will it require some other script?

Maximum Sizes
I have few more questions what is maximum string size, maximum header size for sending e-mails & maximum html e-mail size if we want to send html content in body and set content type tex/html.

How to configure linux server to increase mailbox size so that I can send huge mails. I'm really in a great trouble, It will be of great help to me if any one tells me this maximum sizes and how to handle if maximum size exceeds.

Maximum And Minimum Value
I want to find the maximum and minimum, average value from the text file

<?
$lines = file('./data.txt');

                foreach ($lines as $line) {
                $text_line = explode(":" , $line);


$text_line1 = explode(" " , $text_line[2]);
array_sum($text_line1);
}
?>

This method I am not able to get the array sum..... How to get the numerical value of numbers from strings When I explode the line it is in string format. I should find the array_sum and max() which I values  are in numeric not string.

Getting Maximum Value Inside A Loop
I'm using something like this, to output a table of rows:

// Set max_val
$max_val = 0;
// Do the loop
while ($row = mysql_fetch_assoc($result)) {
$max_val = max($max_val, $row['integer']);
// etc etc
echo $max_val;
// etc etc
}

I want the maximum value of $row['integer'] to be available in every row. The above example does this, with the exception of the first (top) row of the table, where $max_val is then the value of $row['integer'] for that row - not the actual maximum for all rows.

What Is The Maximum Length Of A String?
the php manual gave an example where you can pull an entire file into one string:

$fcontents = join( '', file( 'http://www.php.net' ) );

is there a maximum size that this string can hold, therefore a maximum size file I could import...what happens when this max is reached...error, or just cuts off..?

Maximum Dropdown Size
I have a strange issue with dropdowns. Using php4, mySQL5, Apache 2 on
a fast XP pro PC, I have a form which requires 5 dropdowns populated
with indentical values. I extract the values using SQL and populate 2
variables and use a for-next loop to create the dropdown. The dropdown
contains some 310 items! It works beautifully if I have 1 or 2
dropdowns but as soon as I add more it partially creates the 3rd and
just stops until it times out!
All 5 work because I have altered their positions but it always stops
part way through creating the 3rd dropdown.

I tried an alternative method by doing away with the variables and
constructing the dropdowns with a 'while' statement reading through
the results of my SQL and got exactly the same problem only 2 and a
bit dropdowns.

Stopping it running after a few seconds or several minutes makes no
difference, it seems to reach a certain point and just stop - no error
messages or anything!

I have tried increasing the resourses in my php.ini file but this also
made no difference.

Can anyone suggest an alternative or a fix?

Maximum Integer Size?
I'm trying to figure out how big integers in PHP can be and am having
some difficulty.

My first idea was to try something like this:

<?
for ($bits=0; (1<<($bits+1)) > (1<<$bits); $bits++);
echo $bits;
?>

The result was 30. This, however, is incorrect as the following
demonstrates:

<?
$num = 1<<30;

echo "num = $num
";
echo 'num<<1 = '.($num<<1)."
";
echo 'num*2 = '.($num*2)."
";
?>

That my first idea would return the wrong result doesn't surprise me,
though, since bitwise operators in PHP are treated as arithematic ones
and not logical ones.

So I came up with another test.

<?
for ($bits=0; pow(2,$bits+1) > pow(2,$bits); $bits++);
echo $bits;
?>

In Windows XP, I got 1024 back. On Linux 2.6.13.2 and 2.4.28 (as
reported by phpinfo), all I get are timeout errors. So I decided to
make my script more efficient and hopefully faster:

<?
$x = 2;
$y = 1;
for ($bits=1; ($x*=2) > ($y*=2); $bits++);
echo $bits;
?>

On Windows XP, I again got 1024 back, whereas on Linux, I again got
timeout errors.

Using SELECT To Just Find Row With Maximum Value
how do i do a SELECT statment that will just query a table to find the
row with the maximum of a declared field. for example, if i have a
table of customers and i would like to get the value of the last
customer to register so the SELECT statement would return only one
row, how would i do this?

also, the plan i have is to use a while loop (coz i dont know any
other) to get the colum value of each row:

$select = "SELECT ...
$result = mysql_query($select, $conn); //$conn will be predefined in
the code
while ($row = mysql_fetch_array($result)) {
$date_added = $row['date_added'];
}

the while loop makes sense when outputting many rows but to get the
value of one column in one row, i dont know. it just seems a little
inefficient to use a while loop when i know there is only one row
returned (or will know), is this how all rows from a select statement
are queried or is there a more efficient way of doing this for this
situation?

Maximum Characters In Variables?
My concern now is that I am putting a lot of info into arrays. Is this a bad way to proceed? Or should I use a way to simply include() the file instead of loading it into a variable and printing it to screen? The reason why I have it in an array is for reading different parts of the file... But I can fix it to use the include() function for the heavy parts...

Right now I am storing the same data into a database I downloaded MySQL, made the database and tables and all I need to do is insert the info... But that's another thing. I wanted to not use a database because it will save money for hosting. The site isn't going to be very big (guessing only 50 pages) so I can use only PHP.

Maximum Lenght Of Select Statement
Can anyone tell me what the maximium length of a SELECT statement can be. I am coming from Foxpro where 8100 char was the limit. Part of my program is a query builder and I need to build a query from a series of drop down lists users select values from.

Maximum Size Of Cookie Content
I was wondering if anyone knows whether there is a maximum size limit on a cookie content
If so,

1) Is this a limit per cookie in a single domain? i.e. no single cookie value can exceed XX bytes
2) Is this a limit on all the cookies that get saved under a single domain? i.e. the total size of all the cookies cannot exceed XX bytes
3) Is the limit different from browser to browser?
4) How can I detect what the limit is?

Maximum Execution Time - 30 Seconds?
I'm writing a script that will pour over 30,000 records into my MySQL database, but PHP is bugging out and stopping after just 30 seconds....Only about a quarter of my records are getting put into the DB - is there a way I can temporarily modify the limit to this execution time, and then switch it back later if I need to?

Fetch Maximum Amount Of Chars
I want to fetch a maximum amount of chars, 10 in this case, from my mysql dbase with php. For example: If there is 'Post new topic for forum' in the table, I want to output it to the screen like this: 'Post new..'

Maximum Upload Limit Reached
Hi there I have a form on my website that can allow people to upload files via a web page.
I have the MAX_FILE_SIZE value currently set at the default of 2mb. What I would like to know is, when I am uploading the files what is the easiest way to spit out an error message if the maximimum upload limit gas been reached?

Currently it just goes to a refreshed upload page, but does not inform the user that the limit has gone over. Does anyone know the easiest way to do a check for this and then if it is more than they are allowed inform them??

What Is Maximum File Size For .php Files?
I'm currently working on a 56kb .php file, but my (Windows) PHP interpreter crashes very often when displaying the php script in my browser. What is the maximum size for .php files, and is 56kb actually too big? Should I split it up?

Define The Maximum Result Record
I would like to define the maxmum record that are shown after a search.

Say the total result has 20000 records

I want the result page show only the first 50 out of the 20000, and ignore the rest.

I heard someone say i could "Change the SQL to "SELECT TOP 50...."
I'm not sure how to do that, can anyone help? ....

Maximum Load Time Exeeded..
I know exactly the problem... Basically I changed my method from displaying tutorials per 1000 characters, to adding a function in my bbcode to manually make a "new page". Code:

Maximum Image Height And Width
I have a form where a user can upload a file. s there a way to check the height and width and if the the dimensions fall within a certain criteria the image is uploaded? If not uploaded I want to display and error. I would like images to be no greater than 80 pixels wide by 120 pixels tall.

Catch The Maximum Execution Time Error
I have tried to code a script that allows user to upload a C source file, then compiles and runs.

When i execute the compiled file, i want to impose it a time limit and if the limit exceeded, print " Time limit exceeded".

<form method="POST" enctype="multipart/form-data" action="<?= $PHP_SELF ?>">
<input type="file" name="fn" size="49">
<input type="submit" value="Upload" name="B1" style="button">
</form>
<?php
function excess($errno, $errstr, $errfile, $errline)
{
print "Time limit exceeded";
}
$fn=$_FILES['fn'];
$max=204800;
if (is_uploaded_file($fn['tmp_name'])) {
move_uploaded_file($fn['tmp_name'],"test.cpp");
print "<p>Compiler feedback </p>";
if (is_file("new")) unlink("new");
if (is_file("a.out")) unlink("a.out");
passthru("g++ test.cpp 2>new");
if (!$f=fopen("new","r")) {print "error";}
else {
while (!feof($f)) {
$s=fgets($f);
echo($s);
}
fclose($f);
}
unlink("new");
if (is_executable("a.out")) {
print "<p>Time limit is 60 seconds </p>";
set_time_limit(60);
error_reporting(E_ALL);
set_error_handler('excess');
passthru("./a.out >new");
if (!$f=fopen("new","r")) {print "error";}
print "<p>Your program output </p>";
while (!feof($f)) {
$s=fgets($f);
echo($s);
}
fclose($f);
} else {print "<p>Cannot compile your program </p>";}

}
else {echo "Submission failed";}
?>

it seems like the passthru is not imposed any time limit and the script always ends regardless the source file.

Maximum Execution Time Of 30 Seconds Exceeded
I need to process every character in a file, so i open the file read
in buffers of about 8192 bytes and process each buffer, then i write
the output to another file.

the problem is that with large files(>8Mb) i get a script error(Fatal
error: Maximum execution time of 30 seconds exceeded ).

I acess every character in the buffer with
$chr=ord($bufferIn{$i}); (where $i=0...8192)
seems like all he time the script consumes is in the for loop and the
chr/ord functions.

can i do something to speed things up?
is there any other way of acessing a single characher except $bufferIn{$i}?

Setting A Maximum Limit On A Php/mysql Result?
I am using PHP and MySQL to do this script. I want to have a table that contains only numbers for data and then add them all up as a result to display and that I have accomplished with no problem and then I want to display a percentage of that number to the public however that also I have accomplished with no problem using round()...

The problem is I am trying to set a maximum number that it displays.

I want it to display 1-500 no matter what the number is or the decimal it may have is provided it doesnt exceed 500 but once it does I want it to display 500 as the limit so even if it is say 674 I want it to only display 500. How would I go about doing this?

The sql I am using for the adding is SELECT SUM which works just fine and I am using round( $total_number *.15, 2) to display the percentage number of 15%.

How Can I Increase The Import Maximum Size For MySql
I have a requirement for importing a sql file in my local databse.I
have exported the file from the client database.That file is more than
50mb.I want to import this sql file into my local database.My Maximum
import file size showin as 8mb.I tried to change by editing the ini
file.But still it showing the same.I am using phpMyAdmin.Please tell me
the procedure to change the Maximum File Size for Importing sql file.

Maximum File Size That Can Be Handles With A PHP Script
I am currently trying to debug a script written by my predecessor.
Basically I have an HTML form that is used to upload a file that is
then processed using a PHP script. It has been in frequent use but I
have just been contacted because there is a PDF document that is not
uploading.

I reckon it may have something to do with the file size. All the
previously uploaded files are relatively small (<2MB) but this one is
about 5MB. When I try to upload the file using the script, which I know
uploads the file as it has been in use frequently in the past and I
have tested it with other files, it appears to reject it. When I do the
following (before any processing when the form has been submitted):

echo $_FILES['file']['size'];

....it returns zero (0) indicating that something has gone wrong
although when I do the following:

echo $_FILES['file']['name'];

....it returns the name.

I have tried including a hidden HTML form element MAX_FILE_SIZE and
setting it to exceed the file size (in bytes) but still no luck. Could
it maybe be something in the files content?

How To Remove Oldest Field After Maximum Fields ?
Members of my site have a personal guestbook. I want to give them space for 100 comments. How can I achieve that if item 101 is posted, the oldest is being removed so that 100 items stay in the db ?

the mySQL table PersonalGuestbook:
pgID
pgName
pgComment
pgOwner

FATAL ERROR:Maximum Execution Time Exceeded
I really would like to focus on the business solution this app is supposed to achieve, but there always seems to be a problem with either PHP or MySQL. I finally got everything installed and talking to one another, but now I get this error - Fatal error: Maximum execution time of 30 seconds exceeded in Unknown on line 0.

All I am doing is testing the database connection. The table I am querying has one row of data and I am asking for only one value from that row. The query always takes 30 seconds. I am running this query on my local machine. I am not traversing the net or anything.

Here is the code I am using . I pass in one value called login, to this page :

$cnx=mysql_connect("server:/tmp/mysql.sock","user","") or die(mysql_error);

mysql_select_db("database")or die(mysql_error);

$qry="select SSL from SysUser where username="."'".$login."'";
echo $qry."<br>";
$recset=mysql_query($qry);

while($row=mysql_fetch_object($recset))
{
$ans=$row->SSL;
echo 'SSL= '.$ans;
}

Please help me debug this speed issue.

Maximum Execution Time Of 60 Seconds Exceeded ,how To Solve It?
Fatal error: Maximum execution time of 60 seconds exceeded in H:xampplitehtdocsmlmcardstore.php on line 62

how to solve it?
duno why sometime the browser hang in there....then cause this error msg.

Maximum Execution Time Exceeded // Recursive Function
I am trying to run a recursive function until I quit. But after 30 seconds I get:

Fatal error: Maximum execution time of 30 seconds exceeded

Anyway around this so my function can keep going?

Fatal Error - Maximum Execution Time Of 30 Seconds Exceeded
What could be the cause of this error?

Fatal error: Maximum execution time of 30 seconds exceeded in ht*p://localhost/search.php on line 7

The search.php is an included file. I get this error during the first instance the page is accessed. However, succeeding access does not procedure this error anymore.

The code for search.php (up to line 7) is below:

Maximum Execution Time Of 30 Seconds Exceeded In Creating Thumbnails
I am trying to create thumbnails from 2500 pictures. But I always get
a Maximum execution time of 30 seconds exceeded" at the statement with
the method with imagejpeg or imagedestroy after processing and
creating 500 thumbnails.

Is there anything I can do to avoid this error?

Fatal Error: Maximum Execution Time Of 30 Seconds Exceeded
I'm running a simple mail script on a WinNT server. It gives me the following error:
Fatal error: Maximum execution time of 30 seconds exceeded in E:intranetphone.php on line 22 It does send the email though. Code:

Maximum Execution Time Exceeded With A Mysql Query In A Loop
My script inserts a huge amount of rows to a mysql table and just as easy it deletes them, so to optimize the index numbers i'm trying to make it so that when i'm adding new rows it searches for an empty one to add the new one in.
It's a phpbb mod i'm writting. This is the code i'm trying: Code:

Fatal Error: Maximum Execution Time Of 30 Seconds Exceeded
Im (still) building my stats builder. After much battling I have finally got my code to read in the server log file line by line in reverse without commiting the whole log file to memory by reading the whole thing (if it did the server woul die as the files are HUGE). Once each line has been read the php passes this info to the mysql to be picked up at a later point.

It all works fine, and im happy with my progress.

The only problem? It exceeds the maximum execution time and just stops working! How can I solve this? Is there a way to set the server to let one file run over the 30 secs, or is there a problem in my code??

Fatal Error: Maximum Execution Time Of 30 Seconds Exceeded
I make a code to display numbers 1-20 randomly without repeating any of the numbers. The result is fine but I keep on getting Fatal error: Maximum execution time of 30 seconds exceeded. Personally I don't think PHP will have much trouble going through the loop. Here's the code:

"Maximum Execution Time Of 30 Seconds Exceeded ..."
I'm working on a script that most certainly at times can take longer then 30 seconds to run.. so I need to either alter the hard-coded value, or if theres a command I can apply IN my script (instead of changing the hard-coded value) to get arround this.. that would be great.

Session Limit (maximum File Size Of A Session)
We all now that upon calling session_start(), it will create a file and in this file the session variables that you assigned will be stored. My question is how big can a session file can be? is there a limit or maximum file size for a session file?

Finding How Many There Are In A Var
how can I find out how many newlines there are in a variable?
It's not hard to find out if there is a newline in the var, but I wanna know how many!

Finding Id Value
i am using php and mysql for this. i only want to keep the last 5 entries in the database. so i will add an entry in, which will have an ID value, then i want to delete the id with the lowest value, which in turn will be 6 from the last entry added. so the code will look like this:

$oldid = $newid - 6;
$deletethis = mysql_query("delete from table where id = $oldid");

is there a simple way to find the value of $newid ?

Finding Out An IP
I've been wondering for some time now, how to get every visitor's IP address and log them. Any ideas?

Finding @ In String
What's an easy way to tell if a string contains the @ char?

Finding Referer In PHP
I'm trying to determine the location a user has come from when they access a script of mine (a custom web logging script). I've searched the manual for 'referer' but can't find any relevant references and looking at output from phpinfo doesn't shed any light on which, if any, variables might hold info about where the user has come from.

Finding The Sum In Mysql
What would be the easiet way to add the values of a certain field in every record that it occurs in.

For example, If a person is placing multiple orders on a website and each order is to be shipped to a different location. Each seperate order is being stored in the mysql db and I need to add the shipping costs of all orders together when the user is ready to check out.

Finding The Last Occurance
I'm working on a update at my site. Every file on a part of the site
means something. I want to accomplish some kind of a directory
browseing and at each file displays the realtive info in it.
Anyway... The following part of the code is made for finding the last
occurance of '/' and after i did it, it looked kind of 'primitive' to
me :). Is there any other optimised way of finding the last occurance
of a substring in a string ?

Finding MySQL With 5.0.3
I have loaded PHP MySQL and Apache on windows in the past but recently had to reload my Win XP which is SP2 fully updated.

Have reloaded Apache - fine - and MySQL and MySQLAdministrator - working fine

Loaded PHP 5.0.3 and worked through configuring the ini to show a path to the ext file and so forth - copied some of the dll in the apache file.
Copied many of the addtional modules in pecl into the php/ext directory and uncommented lots of them in the php ini (as suggested in a web tutorial - actually I don't NEED all of them yet)

Installed PHPMyAdmin and configured that and then tried to connect but only get the error message that "cant find mysql"

I tried this twice first with MySQLi and then MySQL set in the PHPMyAdmin configuration.

Same result - some advice on a forum to a similar question suggested copying the dll files to the main php directory (just meant moving them up one in fact) and I did but that does not work either

phpinfo shows lots of the modules but not MySQL or MySQLi

I am rather puzzled - can anyone help this (long winded) problem?


Copyright © 2005-08 www.BigResource.com, All rights reserved