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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T06:39:20+00:00 2026-05-24T06:39:20+00:00

i am having a hard time wrapping my head around how to do this…

  • 0

i am having a hard time wrapping my head around how to do this… i have a select menu i want to display as default and a different one(s) if certain items appear in a shopping cart.

so say i sell dogs and cars. in the cart i have selected one of each. i want one select menu to appear if there are ever any cars in the cart. but if there are ever any dogs in the cart or cats for that matter i want a different select with different options to appear. so car_select would be the default if anything is in the cart…(i sell a lot of stuff) but if a dog appears in the cart then dog_select would replace it.

the way it is written now. the default is the last thing and that is what shows.
(see my comments)

so the code:

<?php
foreach($this->rows as $i => $row){

if (strstr('dogs',$row->dates)) {
$mydates = 'dogs';
} else {$mydates='default';}


//echo $row->dates; this spits out the correct values dogcar


}
//echo $mydates; with a dog and a car in the cart this returns default
//below functions i believe but i think the above is faulty 
?>
<?php 
if ($mydates =='dogs'){
//do something here;} else {

    $type = $this->type;
    foreach($this->extraFields[$type] as $fieldName => $oneExtraField) {
     if ($fieldName != 'pickupdate-rosh'){; ?>
        <tr class="hikashop_checkout_<?php echo $fieldName;?>_line">
            <td class="key">
                <?php echo $this->fieldsClass->getFieldName($oneExtraField);?>
            </td>
            <td>
                <?php 

                        echo $this->fieldsClass->display($oneExtraField,$this->$type->$fieldName,'data['.$type.']['.$fieldName.']'); 
                ?>
            </td>
        </tr>
<?php } ?>
    <?php } ?>
<?php } ?>

i would like to always return car_select unless the presence of dogs or cats etc in the cart.
{edit: i just realized that is not the correct function to use to look for a string.}

  • 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-24T06:39:21+00:00Added an answer on May 24, 2026 at 6:39 am

    It looks like you’re setting $mydates, then overriding it (potentially). This is because you’re setting one variable to one result for all iterations of your foreach loop, and the last iteration will be what the final variable value will be.

    So set $mydates to a default and then change it if the condition is right.

    $mydates='default';
    foreach($this->rows as $i => $row){
        if (strstr('dogs',$row->dates)) {
            $mydates = 'dogs';
        }
        //echo $row->dates; this spits out the correct values dogcar
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm having hard time wrapping my head around this. I have an array called
Having a hard time wrapping my head around this one. I have a Page
I am still having a hard time wrapping my head around this. I want
I'm having a hard time wrapping my head around this and need some help
I'm having a very hard time wrapping my head around this problem (it might
I'm having a hard time wrapping my head around this. I'm loading up an
I'm having a hard time wrapping my head around this, and I'm hoping someone
I am having a hard time wrapping my head around this problem... I am
I'm having a hard time wrapping my head around this Django query. I could
I'm having a hard time wrapping my head around Java generic types. Here's a

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.