Fatal error

Do you have a question? Post it now! No Registration Necessary.  Now with pictures!

Threaded View
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

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)) {
  $contador1 = count($coasters);
  for ($k=0; $k<$contador1; $k++) {
        if(($coasters[$k][0])==$auxi) {

On the other side, if I write something like:
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?

Re: Fatal error

Quoted text here. Click to load it

[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.

Quoted text here. Click to load it

'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?

       WHERE COUNTRY_CODE = '$auxi')

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

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


Re: Fatal error

Thank you for your tip! You were right, '$auxi' should go between ''

Re: Fatal error

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

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

Re: Fatal error

I'm also a novice... I've used COUNT() and it works!

Re: Fatal error

bettina@coaster.ch wrote (in part):
Quoted text here. Click to load it

There are many ways to make this code tighter. Look in
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.
Quoted text here. Click to load it

How is the array $countries defined? You probably shouldn't be using a
second index "[0]".

Quoted text here. Click to load it

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.

Quoted text here. Click to load it

There are ways to let PHP count the number of values in an array.

Quoted text here. Click to load it


Re: Fatal error

On Sun, 03 Jul 2005 01:30:17 -0700, bettina wrote:

Quoted text here. Click to load it

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)

Site Timeline