472,127 Members | 2,093 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,127 software developers and data experts.

Fatal error

I want to list all the countries (147 in total) per continent with the
quantity of beercoasters that each country has. I get the following
message:

Fatal error: Maximum execution time of 30 seconds exceeded in
C:\wampp2\htdocs\main1.php on line 88

Here is the code...perhaps the loop is too big?

......
$contador = count($countries); //quantity of countries
for ($j=0; $j<$contador; $j++) {
$auxi= $countries[$j][0]; // I process each country
$count_coasters = mysql_query("SELECT COUNTRY_CODE FROM COASTERS");
$count =0;
while ($row = mysql_fetch_array($count_coasters, MYSQL_ASSOC)) {
$coasters[$count][0]=$row[0];
$count=$count+1;
}
$contador1 = count($coasters);
$acum=0;
for ($k=0; $k<$contador1; $k++) {
if(($coasters[$k][0])==$auxi) {
$acum=$acum+1;}
}
}

On the other side, if I write something like:
mysql_query("SELECT COUNTRY_CODE FROM COASTERS WHERE COUNTRY_CODE =
$auxi")
in order to get only the coasters from a country and avoid the seconf
loop (with acum) I receive the following message:
Warning: mysql_fetch_array(): supplied argument is not a valid MySQL
result resource in ....

How can I count these records?

Jul 17 '05 #1
6 1460
On 2005-07-03, be*****@coaster.ch <be*****@coaster.ch> wrote:


I want to list all the countries (147 in total) per continent with the
quantity of beercoasters that each country has. I get the following
message:

Fatal error: Maximum execution time of 30 seconds exceeded in
C:\wampp2\htdocs\main1.php on line 88

Here is the code...perhaps the loop is too big?
[snip code]

I won't debug/optimize your code for you, but I will tell you
there is configuration option within PHP to increase the maximum
execution time (look at php.ini).

If more than a 30 second execution time is unacceptable for your
needs, then you'll need to revisit your code.
On the other side, if I write something like:
mysql_query("SELECT COUNTRY_CODE FROM COASTERS WHERE COUNTRY_CODE =
$auxi")
in order to get only the coasters from a country and avoid the seconf
loop (with acum) I receive the following message:
Warning: mysql_fetch_array(): supplied argument is not a valid MySQL
result resource in ....

How can I count these records?


'Not a valid MySQL result resource' = probably a problem
with your query (which you would know if were checking for
errors after communication with your database).

I know no more about your database than the information you've
provided, and I'm not a mind-reader, so this is a stab in the
dark: but what data type is 'COUNTRY_CODE'? Perhaps its data
type requires it to be enclosed in quotes?

(i.e., SELECT COUNTRY_CODE
FROM COASTERS
WHERE COUNTRY_CODE = '$auxi')

I'm probably way off, but it's hard not to be with so little
information.

BTW, you may want to look into the use of "mysql_errno" and
"mysql_error" -- they may be helpful in debugging problems
like this.

HTH,
Justin
Jul 17 '05 #2
Just a quick suggestion, and bear in mind I am a novice at all this,
but maybe the "GROUP BY" function of MySQL could optimise this for you?
(Using either a SUM() or COUNT() function to calculate the Number you
need).

As I said, just a novice and I could be (and probably am) wrong...

Jul 17 '05 #3


be*****@coaster.ch wrote (in part):
I want to list all the countries (147 in total) per continent with the
quantity of beercoasters that each country has. I get the following
message:

Fatal error: Maximum execution time of 30 seconds exceeded in
C:\wampp2\htdocs\main1.php on line 88

Here is the code...perhaps the loop is too big?
There are many ways to make this code tighter. Look in
http://www.php.net/array
for hints on the functions you should be using to do your dirty work.

I will just ask a few questions to get you thinking. From the looks of
your code, it's fairly obvious that you didn't come from a C
programming background.
.....
$contador = count($countries); //quantity of countries
for ($j=0; $j<$contador; $j++) {
$auxi= $countries[$j][0]; // I process each country
How is the array $countries defined? You probably shouldn't be using a
second index "[0]".
$count_coasters = mysql_query("SELECT COUNTRY_CODE FROM COASTERS");
$count =0;
while ($row = mysql_fetch_array($count_coasters, MYSQL_ASSOC)) {
$coasters[$count][0]=$row[0];
$count=$count+1;
}
If you just want to get the number of rows that were retreived in a
previous query, there is a mysql funtions for that.

In your code you're retrieving the data as an associative array, but
you're not using it.
$contador1 = count($coasters);
$acum=0;
for ($k=0; $k<$contador1; $k++) {
if(($coasters[$k][0])==$auxi) {
$acum=$acum+1;}
}
}
There are ways to let PHP count the number of values in an array.

On the other side, if I write something like:
mysql_query("SELECT COUNTRY_CODE FROM COASTERS WHERE COUNTRY_CODE =
$auxi")
in order to get only the coasters from a country and avoid the seconf
loop (with acum) I receive the following message:
Warning: mysql_fetch_array(): supplied argument is not a valid MySQL
result resource in ....

How can I count these records?


Ken

Jul 17 '05 #4
On Sun, 03 Jul 2005 01:30:17 -0700, bettina wrote:
Fatal error: Maximum execution time of 30 seconds exceeded in
C:\wampp2\htdocs\main1.php on line 88

Here is the code...perhaps the loop is too big?


There is a php.ini option called max_execution_time. If set to 0,
the timer is turned off. It can help if you are certain that your
time is spent in the database rather then in the script. Your program
looks much too complicated for comfort and I wouldn't be fiddling
with php.ini just yet.

--
You can get more of what you want with a kind word and a gun than
you can with just a kind word. (Al Kapone)

Jul 17 '05 #5
Thank you for your tip! You were right, '$auxi' should go between ''

Jul 17 '05 #6
I'm also a novice... I've used COUNT() and it works!

Jul 17 '05 #7

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

3 posts views Thread by PeterF | last post: by
8 posts views Thread by Tim Tyler | last post: by
6 posts views Thread by Steve Crawford | last post: by
reply views Thread by leo001 | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.