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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T13:07:43+00:00 2026-06-10T13:07:43+00:00

I want to run a query that gets all the data from a database

  • 0

I want to run a query that gets all the data from a database then have the data split into arrays for each column. With this I intend to dynamically populate html. I am not very experienced with php and could use some assistance with how to put my query into multiple arrays depending on what column it was in.

Example: For the column name I want an array $itemName[] and it will contain every item name in asc order. Then for the image column I want an array $itemImage[] for every image/image url in the same order.

With this I plan to run a for loop where as x increases it will go through each diff array and pull from the specified location. There are no null values in my DB so I don’t need to worry about that.

Any help you can give me with the writing the query into multiple arrays based on the column name is appreciated.

    $mPos = array(mPos1, mPos2, mPos3, mPos4);

    for (x=0; x<4; x++){

    echo "<div class="$mPos[x]"> <div class="$mPos[x] . '_1'">"$title[x]"</div><div class="$mPos1 . '_2'">"$image[x]"</div>

  • 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-10T13:07:45+00:00Added an answer on June 10, 2026 at 1:07 pm

    Still doesn’t make sense for me to separate it that way, but here you go.

    Since you didn’t provide a database/table structure, I will assume your db table got the following columns:

    itemId | itemName | itemImage | itemDescription
    

    In PHP you loop through the result row for row and populate your arrays like

    foreach ( $result AS $row ) {
      $itemNames[$row->itemId] = $row->itemName;
      $itemImages[$row->itemId] = $row->itemImage;
      $itemDescriptions[$row->itemId] = $row->itemDescription;
    }
    

    EDIT: After question was updated and now includes the HTML output, I’d suggest something like this.

    foreach ( $result AS $row ) {
      $items[$row->itemId] = array(
        'name' => $row->itemName,
        'image' => $row->itemImage,
        'description' => $row->itemDescription,
        'price' => $row->itemPrice,
        'link' => $row->itemLink,
      );
    }
    $x = 0;
    while ($x<4) {
      $x++;
      $item = array_shift($items);
      echo '<div class="mPos'.$x.'"> 
        <div class="mPos'.$x.'_1">"'.$item['name'].'"</div>
        <div class="mPos'.$x.'_2">"'.$item['price'].'"</div>
        <div class="mPos'.$x.'_3"><a href="'.$item['link'].'">
          <img src="'.$item['image'].'" /></a>
        </div>
      </div>';
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have created a query block with begin/end and want to run that in
I want the trigger to run after each and every record that gets inserted.
I have the following tables. I want to run a query but I think
I want to run an alter database query on the Schema I am designing
I want run all script from the directory . Like , The directory contains
I have an AJAX call that I want to run against a WCF GET
I have an application that may be run several times a day. Each run
So I have an nhibernate icriteria query that gets the list of results that
Ok, So I have a external php script that get data from a DB
I want to run MySQL query's on command without reloading the page. I think

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.