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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T15:14:18+00:00 2026-05-17T15:14:18+00:00

i am developing an application which have eight advertisement boxes, the advertisement data with

  • 0

i am developing an application which have eight advertisement boxes, the advertisement data with position is stored into the database.

the advertisement module works like first it will check if the particular position exist in the database (i.e 1 to 8) if it finds or not find it will return a Boolean accordingly.

for that reason i am using a user defined function like this.

 function dbgetvar($query) {
             $res = mysql_query($query);
         if( !$res) {
             trigger_error("dbget: ". mysql_error(). " in " .$query);
             return false;
             }
             if( mysql_num_rows($res) == '0' ) {
             return false;
             }
             $row = mysql_fetch_array($res);
             if(!$row) return "";
             return $row;
             }

as i have to make the eight queries i am doing it somewhat like this.

$adbox1 = dbgetvar("SELECT advertisements.id as 1_id, advertisements.pic_brief as 1_brief  FROM advertisements WHERE pos = '1'");
$adbox2 = dbgetvar("SELECT advertisements.id as 2_id, advertisements.pic_brief as 2_brief  FROM advertisements WHERE pos = '2'");
$adbox3 = dbgetvar("SELECT advertisements.id as 3_id, advertisements.pic_brief as 3_brief  FROM advertisements WHERE pos = '3'");
$adbox4 = dbgetvar("SELECT advertisements.id as 4_id, advertisements.pic_brief as 4_brief  FROM advertisements WHERE pos = '4'");
$adbox5 = dbgetvar("SELECT advertisements.id as 5_id, advertisements.pic_brief as 5_brief  FROM advertisements WHERE pos = '5'");
$adbox6 = dbgetvar("SELECT advertisements.id as 6_id, advertisements.pic_brief as 6_brief  FROM advertisements WHERE pos = '6'");
$adbox7 = dbgetvar("SELECT advertisements.id as 7_id, advertisements.pic_brief as 7_brief  FROM advertisements WHERE pos = '7'");
$adbox8 = dbgetvar("SELECT advertisements.id as 8_id, advertisements.pic_brief as 8_brief  FROM advertisements WHERE pos = '8'");

and then i fetch the data like this.

if($adbox1){
    echo "I am found";
}
if(!$adbox1){
    echo "I am not found";
}

although it works fine, it is messed up and a huge queries is piled up. i want to clean and minimize it if possible.

what is your take?

  • 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-17T15:14:18+00:00Added an answer on May 17, 2026 at 3:14 pm

    This should do what you want:

    $query = "SELECT id, pic_brief FROM advertisements WHERE pos BETWEEN 1 AND 8";
    $res = mysql_query($query);
    $adbox = array_fill(1, 8, null);
    while ($row = mysql_fetch_array($res)) {
        $adbox[$row['id'] = $row;
    }
    

    You can access the data as $adbox[1]['id']/$adbox[1]['pic_brief'] and so forth.

    Edit: I’ve updated the code to avoid leaving empty adbox ids.

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

Sidebar

Related Questions

I am developing an application in which i have to get data from .xls
I have heard that when developing application which uses a database you should do
I'm developing an application which currently have hundreds of objects created. Is it possible
I am developing a web application which has Chart Controls. I have developed a
I am developing an application which will be connected to Access database at the
I'm developing an application which will have these classes: class Shortcut { public string
I am developing an iphone application which have a complicated view is to display
i am developing an application in which i have a logout option at all
i am developing an application in which i have to record compass reading. which
When developing an application which consumes an external webservice I have generated the sources

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.