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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T13:09:21+00:00 2026-06-14T13:09:21+00:00

So in my project i need to retrieve some data from a query that

  • 0

So in my project i need to retrieve some data from a query that gives 2 rows(i tested the query in php my admin)

but i am using Object oriented Programing and my method looks like this:

function __construct($pid){

    Sys::database_connect();

    $prod_data = mysql_query("SELECT Produto.produto_id, Produto.nome, Produto.descricao, Produto.pvp, Produto.iva_id, Produto.fornecedor_id, Produto.views, Categoria.nome AS categoria, Imagem.file FROM Produto, Categoria, Imagem WHERE Produto.produto_id = '$pid' AND Produto.categoria_id=Categoria.categoria_id AND Imagem.Produto_produto_id = Produto.produto_id ORDER by Produto.produto_id") or die(mysql_error());

    $array_data = mysql_fetch_array($prod_data);

    $this->produto_id = $array_data['produto_id'];
    $this->nome = $array_data['nome'];
    $this->descricao = $array_data['descricao'];
    $this->pvp = $array_data['pvp'];
    $this->categoria = $array_data['categoria'];

            //this is the picture name (the first one will be the main pic of the product)
    $this->file = $array_data['file'];

    $pre_img_galery = array();
    $max_pics=count($array_data);
    for ($pci_for=0; $pci_for < $max_pics; $pci_for++) { 
        //array_push($pre_img_galery, $array_data['file'][$pci_for]);
        echo $this->$array_data['file'].'<br>';
    }
    $this->img_galery = $pre_img_galery;

}

the database have 2 pictures and that results in 2 rows with different values at the pictures field…

my for loop just echoes the characters of the first file name characters…

how can i define the pictures file name to an array(img_galery)?

my workaround:

function __construct($pid){

    Sys::database_connect();

    $prod_data = mysql_query("SELECT Produto.produto_id, Produto.nome, Produto.descricao, Produto.pvp, Produto.iva_id, Produto.fornecedor_id, Produto.views, Categoria.nome AS categoria, Imagem.file FROM Produto, Categoria, Imagem WHERE Produto.produto_id = '$pid' AND Produto.categoria_id=Categoria.categoria_id AND Imagem.Produto_produto_id = Produto.produto_id ORDER by Produto.produto_id") or die(mysql_error());

    /*while($row = mysql_fetch_array($prod_data)) {
        echo $prod_data['file'].'<br>';
    }*/

    while ($row =  mysql_fetch_array($prod_data)){

    echo $this->produto_id = $row['produto_id'];
    echo $this->nome = $row['nome'];
    echo $this->descricao = $row['descricao'];
    echo $this->pvp = $row['pvp'];
    echo $this->categoria = $row['categoria'];
    //echo $this->online = $array_data['online'];
    echo $this->file = $row['file'];

    $pre_img_galery = array();

    array_push($this->img_galery, $row['file']); 
    echo '<br><br><br>';
    print_r($this->img_galery);
    }

}
  • 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-14T13:09:23+00:00Added an answer on June 14, 2026 at 1:09 pm

    This is what needs to be done, you need to loop through the resultset,

     $prod_data = mysql_query("SELECT Produto.produto_id, Produto.nome, Produto.descricao, Produto.pvp, Produto.iva_id, Produto.fornecedor_id, Produto.views, Categoria.nome AS categoria, Imagem.file FROM Produto, Categoria, Imagem WHERE Produto.produto_id = '$pid' AND Produto.categoria_id=Categoria.categoria_id AND Imagem.Produto_produto_id = Produto.produto_id ORDER by Produto.produto_id") or die(mysql_error());
    
    while($row =  mysql_fetch_array($prod_data) { 
      $pre_img_galery[]['produto_id'] = $row['produto_id'];
       ... //and so on for other indexes per row.
    } 
    

    Note: Mysql_* extensions are deprecated. It would be better to use Mysqli_* or PDO extensions. See this question MySQL vs MySQLi when using PHP and find installation instructions for Mysqli_* here.

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

Sidebar

Related Questions

I'm looking to retrieve some data from MongoDB but I'm unsure of how to
The project I have been given is to store and retrieve unstructured data from
The Junits I have in my project need to load property files from the
for my current project i need to consume messages from many destinations (from hundreds
In my project i need to take an expression input from user as string
Im my current project we need to interface with sharepoint to store and retrieve
So I have a project and we have some data access requirements. This is
I have a project that I have recently started working on seriously but had
I am creating a small project that heavily relies on JavaScript. I come from
SUBJECT: Core Data, can't retrieve/set to my properties from VC's. Most common mistake? Searched

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.