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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T17:23:33+00:00 2026-05-26T17:23:33+00:00

Learning php! I have a sql database which contains a table called ‘images’ which

  • 0

Learning php!

I have a sql database which contains a table called ‘images’ which stores image paths that users would upload. The problem I am having is pulling the image paths from the database to a PHP array, then using the paths to display the images on the screen as a , list item. However when I run the page nothing is displayed.

code for database connection:

include('Database.php');

class Images extends Database{

private $_images = array();

public function __construct(){

  $conn = $this->create_connection('read');     
  $sql = "SELECT image_path FROM 'items' WHERE catagory='tshirt'";      
  $result = $conn->query($sql)or die(mysql_error());        
  while($paths = mysql_fetch_array($result)) {      
    $this->_images[] = $paths['catagory'];      
  }         
}

public function getItems() {        

  return $this->_images;   
}

code for the view:

<ul>
<?php
require ('../model/Images.php');
$imageArray = array();
$images = new Images();
$imageArray[] = $images->getItems();
foreach($ImageArray as $value){
        echo '<li><img src="'.$value.'"></li>';
}   
?>
</ul>

I executed the SQL query using phpmyadmin, which query’s correctly. Also I have simulated the database data by adding the image paths manually to test looping through array.

private $_images = array('./images/tshirt1.jpg', etc, etc);

so I know the foreach loop and query work. The ‘create_connection’ function I have used before, connecting to the same database without any issues, I am a bit
stumped, but I think it may be connected to the mysql_fetch_array section?

Am I using the correct approach? or is there a better way to solve this issue?

Hope someone can point me in the right direction!

Thanks

  • 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-26T17:23:34+00:00Added an answer on May 26, 2026 at 5:23 pm

    change $imageArray[] = $images->getItems(); to $imageArray = $images->getItems(); on top of changes suggested by Digital Precision

    EDIT:

    $imageArray = $images->getItems();
    var_dump( $imageArray );
    foreach($imageArray as $value) {
            var_dump( $value );
            echo '<li><img src="'.$value.'"></li>';
    }
    

    would find where you loose data. I hope it is not related to wrong image path in DB.

    EDIT:

    var_dump always display something… check source of your ‘blank page’ to see what is displaying and if dumped variables are empty try with var_dump( $images ); should show you what is sitting in object, if still property _images is empty array there is problem with constructor, maybe try while ($paths = mysql_fetch_array($result, MYSQL_ASSOC)) or var_dump( $result ); before WHILE LOOP – you loosing data somewhere…

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

Sidebar

Related Questions

I am crash-learning PHP for a project, and I have a ton of stupid
I have committed to learning C now, I'm good with Python/PHP/Bash but I've decided
I am pretty new to php, but I am learning! I have a simple
I have been making a database and learning along the way. I recently got
I'm interested in learning more about design practices in PHP for Database Abstraction &
I have been learning php, by just plugging away at it. I was hoping
I have been learning php for sometime now. Besides reading books and doing tutorials
I have developed a membership script with php for learning and I have confused
Bear with me, I have been only learning PHP for only a few weeks,
I have been learning syntax for PHP and practicing it. I come from a

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.