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 7307823
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T23:28:27+00:00 2026-05-28T23:28:27+00:00

I have a problem in a class I can’t solve, the loop breaks in

  • 0

I have a problem in a class I can’t solve, the loop breaks in getAlojamiento() when I call getImagenes() inside the while. In this case getAlojamiento() returns only one row, it should return all the rows. Here are the methods involved:

 //THIS GETS THE ROWS FROM A TABLE AND RETURN AN ARRAY, IF $id IS SET, CHECKS IF id_asoc == $id
 public function getImagenes($table, $id=false){
    $return = '';
    //checks if id id == true
    if($id){
        $sql="SELECT * FROM $table WHERE id_asoc = '$id' ORDER BY id DESC";
    }else{
        $id = '';
        $sql="SELECT * FROM $table ORDER BY id DESC";
    }
    //this make the sql request (returns an array)
    if(!$this->MySQLQuery($sql)){
        $return = false;
        }else{
        if($this->dbNumberRows == 0){ //cheks if there are results
            $return = false;
        }else{ //if has results makes and fills an array
            $items = array();
            while($f = mysql_fetch_object($this->dbResults)){
                $items[$f->id]['id'] = $f->id;
                $items[$f->id]['id_asoc'] = $f->id_asoc;
                $items[$f->id]['comentario'] = htmlentities($f->comentario);
                $items[$f->id]['nombre'] = htmlentities($f->nombre);
                }
            $return = $items;
        }
    }
    return $return;
}


 //THIS GETS THE ROWS FROM A TABLE AND RETURN AN ARRAY
   public function getAlojamiento($id=false){
        $return = '';
        //checks if id id == true 
        if($id){
            $sql="SELECT * FROM tb_alojamiento WHERE id = '$id'  LIMIT 1";
        }else{
            $id = '';
            $sql="SELECT * FROM tb_alojamiento ORDER BY titulo ASC";
        }
    //this make the sql request (returns an array)
    if(!$this->MySQLQuery($sql)){
        $return = false;
        }else{
        if($this->dbNumberRows == 0){ //cheks if there are results
            $return = false;
        }else{ //if has results makes and fills an array
            $items = array();
            while($f = mysql_fetch_object($this->dbResults)){
                $imagenes_arr = $this->getImagenes('tb_alo_imagenes', $f->id); //this is causing the break
                $items[$f->id]['id'] = $f->id;
                $items[$f->id]['titulo'] = $f->titulo;
                $items[$f->id]['telefono'] = $f->telefono;
                $items[$f->id]['descripcion'] = $f->descripcion;
                $items[$f->id]['email'] = $f->email;
                $items[$f->id]['url'] = $f->url;
                $items[$f->id]['direccion'] = $f->direccion;
                $items[$f->id]['ubicacion'] = $f->ubicacion;
                $items[$f->id]['coordenadas'] = $f->coordenadas;
                $items[$f->id]['disponibilidad'] = $f->disponibilidad;
                $items[$f->id]['tarifas'] = $f->tarifas;
                $items[$f->id]['servicios'] = $f->servicios;
                $items[$f->id]['theme'] = $f->theme;
                $items[$f->id]['premium'] = $f->premium;
                $items[$f->id]['img_ppal_id'] = $f->img_ppal_id;    
                $items[$f->id]['imagenes'] = $imagenes_arr;


            }
            $return = $items;
        }
    }
    return $return;
}
  • 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-28T23:28:28+00:00Added an answer on May 28, 2026 at 11:28 pm

    A simple solution to avoid having the first mysql query affect other queries is to complete it first:

    //first loop over the result set from first query
    
    while($f = mysql_fetch_object($this->dbResults))
    {
        //note: no call to $this->getImagenes here!
        $items[$f->id]['id'] = $f->id;
        $items[$f->id]['titulo'] = $f->titulo;
        ....
    }
    
    //only now you fetch the images in a second pass 
    
    foreach( $items as $id => $item )
    {
        $items[$id]['imagenes'] = $this->getImagenes('tb_alo_imagenes', $id);
    }
    
    //return the complete $items array
    
    $return = $items;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

i have a problem with this class. the goal is to make the main
I have a problem with the Java BigInteger class: I can't paste a large
I have problem with remove() method. I can't remove $(this) object. My code is:
This time I have problem with virtual fields. I have core class for my
I have an interesting problem. I'd like to create a generic class that can
I have a class Node. This class can add or remove other nodes relative
I have the following problem: //A.h class A { //... // this is the
Good day, I have the following problem: class B extends class A and methods
I have a problem with ViewHolder class. I use ViewHolder to improve my List
I have problem organizing my unittest based class test for family of tests. For

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.