Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 4535724
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 21, 20262026-05-21T14:26:30+00:00 2026-05-21T14:26:30+00:00

Ok, so I have this function, wich I use many time in my page,

  • 0

Ok, so I have this function, wich I use many time in my page, but only work when I call the function one time, or if a function with results i call it first…

this is the query:

$resultClientes = mysql_query("SELECT nombre.idNombre
  , nombre.nombre AS nombreNombre
  , comuna.nombre AS nombreComuna
  , giro.nombre AS nombreGiro
  , provincia.nombre AS nombreProvincia
  , provincia.region_idRegion AS idRegion 
FROM nombre 
INNER JOIN comuna ON nombre.Comuna_idComuna = comuna.idComuna 
INNER JOIN giro ON nombre.Giro_idGiro = giro.idGiro 
INNER JOIN provincia ON comuna.Provincia_idProvincia = provincia.idProvincia 
ORDER BY nombreProvincia, nombreComuna, nombreGiro, nombreNombre");

and this is the function:

function listaClientesPorRegion($numReg,$query){
  $nombreProvincia = "";
  $nombreComuna = "";
  $nombreGiro = "";
  $nombreNombre = array();
  $i=0;

  while ($row = mysql_fetch_assoc($query)) {
    if($row['idRegion']== $numReg){
      if ($nombreProvincia == $row['nombreProvincia']) {
        if ($nombreComuna == $row['nombreComuna']) {
          if ($nombreGiro == $row['nombreGiro']) {
            $nombreNombre[] = $row['nombreNombre'];
          }
          else { //nombreGiro
            echo '<li>' . implode('</li><li>', $nombreNombre).'</li></ul></li></ul>';
        $nombreGiro = $row['nombreGiro'];
        echo '<ul class="clientes_giro"><li>'.$nombreGiro.'<ul 
                   class="clientes_nombre">';
        $nombreNombre = array($row['nombreNombre']);
          }
        }
        else { // nombreComuna
          echo '<li>' . implode('</li><li>', $nombreNombre).
               '</li></ul></li></ul></li></ul>';
          $nombreComuna = $row['nombreComuna'];
          echo '<ul class="clientes_comuna"><li>'.$nombreComuna;
          $nombreGiro = $row['nombreGiro'];
          echo '<ul class="clientes_giro"><li>'.$nombreGiro.'<ul
                class="clientes_nombre">';
          $nombreNombre = array($row['nombreNombre']);
        }
      }
      else { // nombreProvincia
        if (!empty($nombreNombre)) {
          echo '<li>' . implode('</li><li>', $nombreNombre).
               '</li></ul></li></ul></li></ul></li></ul></div>';
        }
        $class = $i++ % 2 ? 'clientes_floatEven' : 'clientes_floatOdd';

        $nombreProvincia = $row['nombreProvincia'];
        echo '<div id="'.$class.'"><ul class="clientes_provincia">
              <li><div class="underline_yellow">'.$nombreProvincia.'</div>';
        $nombreComuna = $row['nombreComuna'];
        echo '<ul class="clientes_comuna"><li>'.$nombreComuna;
        $nombreGiro = $row['nombreGiro'];
        echo '<ul class="clientes_giro"><li>'.$nombreGiro.'<ul 
        class="clientes_nombre">';
        $nombreNombre = array($row['nombreNombre']);
      }
    }
  }
  if (!empty($nombreNombre)) {
    echo '<li>' . implode('</li><li>', $nombreNombre).
         '</li></ul></li></ul></li></ul></li></ul></div>';  
 }
}

and this is part of the html

<div id="atacama"> 
  <ul class="regiones_nomb_container"> 
    <li class="atacama"></li>
  </ul>
  <?php
    listaClientesPorRegion(3,$resultClientes);
  ?>
</div>

<div id="coquimbo"> 
  <ul class="regiones_nomb_container"> 
    <li class="coquimbo"></li>
  </ul> 
  <?php
    listaClientesPorRegion(4,$resultClientes);
  ?>
</div>

<div id="valparaiso"> 
  <ul class="regiones_nomb_container"> 
    <li class="valparaiso"></li>
  </ul>
  <?php
    listaClientesPorRegion(5,$resultClientes);
  ?>
</div>

At first I tried the function with only one time and with a query that I knew would have records, like listaClientesPorRegion(9, $resultClientes), then I tried with a number I knew would not have records, both worked, so I called multiple times for all the divs in my website, but now is not working, I have no idea why…
(I’m new in php and stuff), thank you for your help!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-21T14:26:31+00:00Added an answer on May 21, 2026 at 2:26 pm

    There are a handful of issues with the code.
    First, it looks like you are sending the IdRegion and the results of the query to your function as ($numReg,$query).
    This means you will have to parse through every record in the results set to display what you are looking for.

    Move the query into the function and only pass the idRegion.
    Second, do some error checking on the $numReg to make sure something gets passed.
    Third, put the $numReg value in the query to limit the results automatically.
    That way you only pull the records you intend to use.

    Here is the sample code:

    function listaClientesPorRegion($numReg = null){
        if(!$numReg) {
            // handling here (i.e. return null, echo 'Error!';, etc.)
        }
        $nombreProvincia = "";
        $nombreComuna = "";
        $nombreGiro = "";
        $nombreNombre = array();
        $i=0;
    
        $resultClientes = mysql_query("SELECT nombre.idNombre
          , nombre.nombre AS nombreNombre
          , comuna.nombre AS nombreComuna
          , giro.nombre AS nombreGiro
          , provincia.nombre AS nombreProvincia
          , provincia.region_idRegion AS idRegion 
        FROM nombre 
        WHERE provincia.region_idRegion = $numReg 
        INNER JOIN comuna ON nombre.Comuna_idComuna = comuna.idComuna 
        INNER JOIN giro ON nombre.Giro_idGiro = giro.idGiro 
        INNER JOIN provincia ON comuna.Provincia_idProvincia = provincia.idProvincia 
        ORDER BY nombreProvincia, nombreComuna, nombreGiro, nombreNombre");
    
        while ($row = mysql_fetch_assoc($query)) {
       ...
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

No related questions found

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.