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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T06:03:37+00:00 2026-05-26T06:03:37+00:00

I have few drop down boxes from where I can get an id of

  • 0

I have few drop down boxes from where I can get an id of a category. For example, from drop down box 1, i get $cat1, from box 2 i get $cat2 and so on.

Then I want to get the entries from db for each of the cat id. Currently I am repeating same code for each of the variable, like:

<?
$cat1 = 1;
$cat2 = 3;
$cat3 = 4;
$cat4 = 8;

<? if ($var1 != ""){ ?> 
    <div>
        Entries for <? echo $var1; ?>           
        ..
    </div>
<? } ?>

<? if ($var2 != ""){ ?> 
    <div>
        Entries for <? echo $var2; ?>
        ..
    </div>
<? } ?>

<? if ($var3 != ""){ ?> 
    <div>
        Entries for <? echo $var3; ?>
        ..
    </div>
<? } ?>

I’d like to know if I can use a loop and avoid writing code for each variable.

  • 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-26T06:03:38+00:00Added an answer on May 26, 2026 at 6:03 am

    Try

    <?
    $cats = array(1,3,4,8);
    foreach($cats as $value) {
     if($value != "") {
     ?>
       <div>Entries for <?= $value; ?></div>
     <?
     }
    }
    ?>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to create a drop-down box with a few values. I don't want
I have a page on my site which has multiple drop down boxes as
I have 3 drop down boxes, created using the HTML select tag. On page
I have an ASP.NET MVC application with quite a few drop-down lists and multi-select
I have an iframe which contains a few select drop-down lists for data entry.
I have few nested DIVs at page. I want to add event only for
I have few Question for which I am not able to get a proper
I have a drop down in a MVC View, which is some thing like
I have a drop down in one of my views, allowing me to select
Drop-down lists, menus and combo boxes are all very common user interface elements. Users

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.