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

  • SEARCH
  • Home
  • 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 8934659
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T09:50:25+00:00 2026-06-15T09:50:25+00:00

I have used PHP for several years now, and OOP, classes and such are

  • 0

I have used PHP for several years now, and OOP, classes and such are not an alien concept to me, but for some reason, there is something (not) happening that i just can get my head around, its 1am here now, and it might have something to do with it but please.. someone put me out of my midnight misery !!

I have a PHP DB Class, and a populated DB, and several functions at play here.. I KNOW there are over 50 lines in the database that shoud be returned, but i keep getting just one !!

Heres my class for DB Connection..

Class DbConnect { 

var $host = 'localhost'; 
var $user = 'user'; 
var $password = 'pass'; 
var $database = 'db'; 
var $persistent = false; 

var $conn = NULL; 

var $result= false; 
var $error_reporting = false; 

/*constructor function this will run when we call the class */ 

function DbConnect () {

    $host = 'localhost'; 
    $user = 'user'; 
    $password = 'pass'; 
    $database = 'db'; 
    $persistent = false;
    $error_reporting = true;

    $this->host = $host; 
    $this->user = $user; 
    $this->password = $password; 
    $this->database = $database; 
    $this->persistent = $persistent; 
    $this->error_reporting = $error_reporting;

} 

function open() { 

    if ($this->persistent) { 

        $func = 'mysql_pconnect'; 

    } else { 

        $func = 'mysql_connect'; 

    }             

    /* Connect to the MySQl Server */ 

    $this->conn = $func($this->host, $this->user, $this->password); 

    if (!$this->conn) { 

        return false; 

    } 

    /* Select the requested DB */ 

    if (@!mysql_select_db($this->database, $this->conn)) { 

        return false; 
    } 

    return true; 
} 

/*close the connection */ 

function close() { 

    return (@mysql_close($this->conn)); 

} 

/* report error if error_reporting set to true */ 

function error() { 

    if ($this->error_reporting) { 

        return (mysql_error()) ; 

    } 

} 

function query($sql) { 

    $this->result = @mysql_query($sql, $this->conn); 

    return($this->result != false); 

}

function affectedrows() { 

    return(@mysql_affected_rows($this->conn));

} 

function numrows() { 

    return(@mysql_num_rows($this->result)); 

}

function fetchobject() { 

    return(@mysql_fetch_object($this->result, MYSQL_ASSOC)); 

}

function fetcharray() { 

    return(mysql_fetch_array($this->result)); 

 } 

 function fetchassoc() { 

     return(@mysql_fetch_assoc($this->result)); 
 } 

 function freeresult() { 

      return(@mysql_free_result($this->result)); 

 } 

}

ok, and here’s my actual query function…

function getAllProperties() {

    $propertyArray = array();
    $db = new DbConnect(); 
    $db->open() or die($db->error());      
    $db->query("select * from properties");
    $details=$db->fetchassoc();
    // UNCOMMENT FOR DEBUG ---->> var_dump($details);
    $a=0;
    foreach($details as $field=>$value) {

        if($field == 'pid') {
            $propertyArray[$a] = getPropertyDetails($value);
            $a++;
        }
    }
    $db->close();
    return $propertyArray;
}

function getPropertyDetails($pid) {

$propertyArray = array();
$propertyDetails = array();
$propertyFeatures = array();
$propertyImages = array();
    $propertyReviews = array();
    $propertyBookings = array();

    $db = new DbConnect(); 
    $db->open() or die($db->error());

    // property details
    $db->query("select * from properties where pid = $pid");
$a = 0;
    while($details=$db->fetchassoc()) {
    $propertyDetails[$a]['pid'] = $details['pid'];
            $propertyDetails[$a]['name'] = $details['name'];
    $propertyDetails[$a]['description'] = $details['description'];
    $propertyDetails[$a]['rooms'] = $details['rooms'];
    $propertyDetails[$a]['baths'] = $details['baths'];
    $propertyDetails[$a]['sleeps'] = $details['sleeps'];
    $propertyDetails[$a]['rental'] = $details['rental'];
    $propertyDetails[$a]['sale'] = $details['sale'];
    $propertyDetails[$a]['forsale'] = $details['forsale'];
    $a++;
    }

    // property details
    $db->query("select * from images where pid = $pid order by weight asc");
$a = 0;
    while($details=$db->fetchassoc()) {
            $propertyImages[$a]['src'] = $details['img'];
    $propertyImages[$a]['thumb'] = $details['thumb'];
    $propertyImages[$a]['alt'] = $details['description'];
    $propertyImages[$a]['weight'] = $details['weight'];
    $propertyImages[$a]['iid'] = $details['iid'];
    $propertyImages[$a]['pid'] = $details['pid'];
    $a++;
    }

    // property details
    $db->query("select * from property_features pf join features f on f.fid = pf.fid where pid = $pid");
$a = 0;
    while($details=$db->fetchassoc()) {
    $propertyFeatures[$a]['fid'] = $details['fid'];
    $propertyFeatures[$a]['name'] = $details['name'];
    $propertyFeatures[$a]['description'] = $details['description'];
    $propertyFeatures[$a]['img'] = $details['img'];
    $propertyFeatures[$a]['pid'] = $details['pid'];
    $a++;
    }

    // property details
    $db->query("select * from testimonials where pid = $pid");
$a = 0;
    while($details=$db->fetchassoc()) {
    $propertyReviews[$a]['tid'] = $details['tid'];
    $propertyReviews[$a]['pid'] = $details['pid'];
    $propertyReviews[$a]['by'] = $details['by'];
    $propertyReviews[$a]['body'] = $details['body'];
    $propertyReviews[$a]['stars'] = $details['stars'];
            $propertyReviews[$a]['cid'] = $details['cid'];
    $a++;
    }

    // property details
    $db->query("select * from availability where pid = $pid");
    $b = 0;
    while($bookings=$db->fetchassoc()) {
            $propertyBookings[$b]['aid'] = $bookings['tid'];
            $propertyBookings[$b]['pid'] = $bookings['pid'];
            $propertyBookings[$b]['from'] = $bookings['by'];
            $propertyBookings[$b]['to'] = $bookings['body'];
            $propertyBookings[$b]['cid'] = $bookings['cid'];
            $b++;
    }

    $db->close();

$propertyArray = array(
    'details' => $propertyDetails,
    'images'  => $propertyImages,
    'features'=> $propertyFeatures,
            'reviews' => $propertyReviews,
            'bookings'=> $propertyBookings
            );

    return $propertyArray;

}

My expectation would be to see a nice fat array with loads of properties in ( by that i mean buildings) and loads of sub arrays and a bunch more data in there too… what i get is this measly offering…

array(1) { 
[0]=> array(5) { 
    ["details"]=> array(1) { 
        [0]=> array(9) { 
            ["pid"]=> string(1) "1" 
            ["name"]=> string(12) "Casa De Paul" 
            ["description"]=> string(134) "a small, dark, damp building in the middle of nowhere with no shops, or roads, lots of spiders and a spikey bed for almost one person." 
            ["rooms"]=> string(1) "2" 
            ["baths"]=> string(1) "1" 
            ["sleeps"]=> string(1) "4" 
            ["rental"]=> string(4) "0.00" 
            ["sale"]=> string(4) "0.00" 
            ["forsale"]=> string(1) "0" } } 
    ["images"]=> array(0) { } 
    ["features"]=> array(0) { } 
    ["reviews"]=> array(0) { } 
    ["bookings"]=> array(0) { } } } 

just for info: when i query the DB in phpMyAdmin using “Select * from properties” i get all the results i would have expected ….

theres something ive missed – or over baked, and i cant see it and my head is about to go POP !

Thanks in advance peoples of SO 😀

  • 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-06-15T09:50:26+00:00Added an answer on June 15, 2026 at 9:50 am

    It seems that after you call mysql_fetch_assoc($this->result) on the first details query and looped through the resource result already so the pointer is no longer pointing at any rows.

    If you decide to loop through the same resource result again, the function will always return false because it will assume there are no more rows.

    Try to reset your pointer after every loops:

    // Reset Pointer.
    mysql_data_seek( $this->result );
    
    $db->query("select * from images where pid = $pid order by weight asc");
    $a = 0;
    while($details=$db->fetchassoc()) {
        $propertyImages[$a]['src'] = $details['img'];
        $propertyImages[$a]['thumb'] = $details['thumb'];
        $propertyImages[$a]['alt'] = $details['description'];
        $propertyImages[$a]['weight'] = $details['weight'];
        $propertyImages[$a]['iid'] = $details['iid'];
        $propertyImages[$a]['pid'] = $details['pid'];
        $a++;
    }
    
    mysql_data_seek( $this->result );
    
    // etc....
    

    Then continue your next query and fetch data loops.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Having used PHP GD for some time I have decided to move to Imagemagick.
I want to get Httpresponse body in php.I have used pear.but it gives me
It's been several years since I have used regular expressions, and I was hoping
I have several php pages that have forms used to submit data. My typical
Writing a PHP app and have several classes that only have static methods (no
Having used some PHP frameworks such as Codeigniter and Kohana for some smaller sites,
I have several SELECT statements on a PHP page, and I used Dreamweaver to
I have used PHP array for HTML select, then I put my codes in
I have recently used a PHP pagination tutorial, Pagination - what it is and
Tech used: PHP 5.3.10 Hi, I have an array (example below) I need to

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.