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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T14:11:25+00:00 2026-05-20T14:11:25+00:00

I am trying to select multiple rows from the database and then separate the

  • 0

I am trying to select multiple rows from the database and then separate the rows into array values so I can use them throughout my code.

This is what I have right now…

$result = mysql_query("SELECT url, image, placement FROM advert
 WHERE user='1'") or die(mysql_error());

//This grabs 3 rows with placement name equal to 'sideadtop','sideadmiddle','sideadbottom'

 ($row =  mysql_fetch_array($result, MYSQL_NUM));

$keytop = array_search('sideadtop', $row);
$sideadtop['url'] == $row[$keytop]['url'];
$sideadtop['image'] == $row[$keytop]['image'];

$keymiddle = array_search('sideadmiddle', $row);
$sideadmiddle['url'] == $row[$keymiddle]['url'];
$sideadmiddle['image'] == $row[$keymiddle]['image'];

I am trying to get the url and image values for each ad placement value. I am not sure how the output for the mysql query is sent to php. Is it sent as a multideminsional array or just a array?

Should I be calling individual MySQL queries or is there an easy way to call multiple rows and than separate them after?

  • 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-20T14:11:25+00:00Added an answer on May 20, 2026 at 2:11 pm

    mysql_fetch_* will only fetch one row. I think what you want is this:

    $result = mysql_query("SELECT url, image, placement FROM advert WHERE user='1'") 
    or die(mysql_error());
    
    $adverts = array();
    
    while(($row = mysql_fetch_assoc($result))) {
        $adverts[$row['placement']] = $row;
    }
    

    It will create an array like this:

    Array(
      'sideadtop' => Array(
           'url' => ..., 
           'image' => ...,
           'placement' => ...
       ),
       'sideadmiddle' => Array(...),
       'sideadbottom' => Array(...)
    )
    

    You can access the individual adverts with $adverts['sideadtop'], $adverts['sideadmiddle'], etc.

    Imo this is a better approach than creating a variable for each element.

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

Sidebar

Related Questions

I'm trying to select multiple values from 2 columns. I can get the query
I am trying to select some fields from one table and insert them into
I'm trying to use CheckBoxes within a GridView's TemplateField to select multiple entries from
I'm trying to select multiple tables and want to display them as if they
I'm trying to select data from a table defined similar to the following :
I'm trying to select a random 10% sampling from a small table. I thought
I'm trying to select a column from a single table (no joins) and I
I'm trying to select the used range. I get the worksheet's UsedRange, then I
I'm trying to select the name field from the author node in an ATOM
I am trying to select certain fields from my entity to be used as

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.