Jump to content

Foreach on so many subcategories and so many products


Recommended Posts

I'm trying to get a list of child categories with their respective products inside them. The code works if I have 50 products and 3 categories. The problem is that: if I have more than 1500 products divided by 6 categories, my code returns an error page for the necessary waiting time for loading (I think).

When I launch the code, the whole site is blocked and after 2 minutes and 30 seconds it gives me back:
 

Quote

 

Internal Server Error The server encountered an internal error or misconfiguration and was unable to complete your request.

Please contact the server at [email protected] to inform them of the time this error occurred, and the actions you performed just before this error.

More information about this error may be available in the server error log.

 

 

This is my code:

$prodotti = '';
        foreach ($children as $chi){
        $prodotti .= '
        <div style="">
        <table style="width: 100%">
            <tr>
                <th align="left">
                  '.$chi[name].'
                </th>
                <th></th>
                <th></th>
            </tr>
            <tr>
               <th style="width: 80%">
                  Prodotto
               </th>
               <th align="right" style="width: 10%">
                  N. Valori
               </th>
               <th align="right" style="width: 10%">
                  Prezzo
               </th>
            </tr>';
            foreach ($products as $pro){
                if(in_array($chi[id_category],Product::getProductCategories($pro[id_product]))){
                      $prodotti .= '
                        <tr>
                           <td style="font-size: 9pt; color: #9E9F9E">
                              '.$pro[name].'
                           </td>
                           <td align="right" style="font-size: 9pt; color: #9E9F9E">
                           ...
                           </td>
                           <td align="right" style="font-size: 9pt; color: #9E9F9E">
                            '.$my_currency_iso_code.'
                            '.$pro[price].'
                           </td>
                        </tr>'; 
                }
            }
        $prodotti.='
        </table>
    </div>';   
        }

Thanks, greetings.

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...