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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T05:23:39+00:00 2026-06-13T05:23:39+00:00

I hope I haven’t duplicated this topic I’m sure it’s on here I just

  • 0

I hope I haven’t duplicated this topic I’m sure it’s on here I just can’t find it.

I have a product with a bunch of sizes, the availability of these sizes is stored in a database, e.g. 0 = none in stock, 1 and more = in stock.

When not available I’d like the size to not display in a drop down. When 1 and more are available they display… I can get the size to display when 1 or more but displays “0” when = “0” Which I understand but not sure how to not display. Think I over complicated the explanation there :S

$size_available = "";
$size_6w = $row["size_6w"];
$size_7w = $row["size_7w"];
$size_8w = $row["size_8w"];

$dropdown = "<select class='product-select' name='size' id='size'>";

if ($size_6w > 0) {
    $size_6w = "6w";
}
if ($size_7w > 0) {
    $size_7w = "7w";
}
if ($size_8w > 0)
    $size_8w = "8w";
}

$size=array("$size_6w","$size_7w","$size_8w");

foreach ($size as $size_available)
{
    $dropdown .= "<option value='$size_available'>$size_available</option>";
}

$dropdown .= "\r\n</select>";

Output is a simple echo:

echo $dropdown

Should I be using an else statement? If so how would you suggest I use it to output nothing?

Thanks

  • 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-13T05:23:40+00:00Added an answer on June 13, 2026 at 5:23 am

    Check if the size is greater than or equal to 1 and only then display the option to the user.

    Here is how I would implement this:

    <?php
    
    $sizes = array(
        '6w' => $row["size_6w"],
        '7w' => $row["size_7w"],
        '8w' => $row["size_8w"]
    );
    
    $dropdown = "<select class='product-select' name='size' id='size'>";
    
    foreach ($sizes as $size => $available)
    {
        if ($available >= 1)
            $dropdown .= "<option value='$size'>$size</option>\n";
    }
    
    $dropdown .= "\r\n</select>";
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I haven't seen this question anywhere else, I hope someone can help. I have
I haven't been able to find a definitive answer and I hope someone can
I have looked here and in google search and I haven't find something relative
I hope someone can help me with this Javascript. I have an Object called
I'm trying to learn WPF, so here's a simple question, I hope: I have
Hope I'm asking this correctly: I have a project Projects.Client I have my class
I hope this makes enough sense and someone can give me some feedback on
This is my first question here, so I hope that I am providing enough
I've looked around and haven't managed to find out how to do this, even
I hope the subject is clear enough, I haven't found anything specifically about this

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.