I need help for dropdown menu from MySQL


#1

I am trying to pull out of the database, but there are 5 drop-down menus each time and the same types appear in each menu. I did not find where the problem originated. Could you help?

<div class="mkdf-membership-input-holder">
<label class="mkdf-membership-input-label" for="property_type"><?php esc_html_e( 'Property Type', 'mkdf-real-estate' ); ?></label>

<?php $property_terms = mkdf_re_get_property_terms_list('property-type'); if (is_array($property_terms) && count($property_terms)) { ?>

<div class="mkdf-grid-row">
<?php foreach ($property_terms as $property_term) { ?>

<div class="mkdf-grid-col-3">

<select name="property_type" id="property_term">

<option value="<?php echo esc_attr($property_term['id'])?>"><?php esc_html_e($property_term['name'],'mkdf-real-estate'); ?></option>
<option value="<?php echo esc_attr($property_term['id'])?>"><?php esc_html_e($property_term['name'],'mkdf-real-estate'); ?></option>
<option value="<?php echo esc_attr($property_term['id'])?>"><?php esc_html_e($property_term['name'],'mkdf-real-estate'); ?></option>
<option value="<?php echo esc_attr($property_term['id'])?>"><?php esc_html_e($property_term['name'],'mkdf-real-estate'); ?></option>
<option value="<?php echo esc_attr($property_term['id'])?>"><?php esc_html_e($property_term['name'],'mkdf-real-estate'); ?></option>
<option value="<?php echo esc_attr($property_term['id'])?>"><?php esc_html_e($property_term['name'],'mkdf-real-estate'); ?></option>

<label class="mkdf-membership-input-label" for="mkdf-feature-<?php echo esc_attr($property_term['id'])?>">
<span class="mkdf-label-view"></span>
<span class="mkdf-label-text">
<?php echo esc_html_e($property_term['name'])?>
</span>	
</label>						
</select>
</div>
<?php } ?>
</div>
<?php } ?>
</div>

#2

Hi @loungexl welcome to the forums.

<off-topic>
When you post code in the forum, you need to format it. To do so you can either select all the code and click the </> button, or type 3 backticks ``` on a separate line both before and after the code block.

I have done it for you this time.
</off-topic>


#3

You have the foreach loop before your select element, so you are in fact creating a select dropdown for each of your values.

Try this instead:

<select name="property_type" id="property_term">

<?php foreach ($property_terms ad $property_term) : ?>

   <option value="<?php echo esc_attr($property_term['id']); ?>"><?php esc_html_e($property_term['name'],'mkdf-real-estate'); ?></option>

<?php endforeach; ?>

</select>

#4

Thank you gandalf :smiley:


#5

Thank you so much. Finally happened :rofl::star_struck:


#6

the list view is okay as below, but when selected from the list it does not send the selected one to MySQL.

<div class="mkdf-membership-input-holder">
<label class="mkdf-membership-input-label" for="property_type"><?php esc_html_e( 'Property Type', 'mkdf-real-estate' ); ?></label>
<?php $property_terms = mkdf_re_get_property_terms_list('property-type'); if (is_array($property_terms) && count($property_terms)) { ?>
<div class="mkdf-grid-row">
<div class="mkdf-grid-col-3">
<select name="property_type" id="property_term">
<?php foreach ($property_terms as $property_term) { ?>
<option value="<?php echo esc_attr($property_term['id'])?>"><?php esc_html_e($property_term['name'],'mkdf-real-estate'); ?></option>
<label class="mkdf-checkbox-label" for="mkdf-feature-<?php echo esc_attr($property_term['id'])?>">
<span class="mkdf-label-view"></span>
<span class="mkdf-label-text"></span>
<?php echo esc_html($property_term['name'])?>
</label>
<?php } ?>						
</select>
</div>
</div>
<?php } ?>
</div>	

#7

Where is your PHP code that processes the values from the form? Without that code, nothing will go to the database.


#8

iā€™m checking again. thanks.


#9

Thank you for waking me up. I tried to edit the code as follows.

<div class="mkdf-membership-input-holder">
<label class="mkdf-membership-input-label" for="property_type"><?php esc_html_e( 'Property Type', 'mkdf-real-estate' ); ?></label>
<?php $property_terms = mkdf_re_get_property_terms_list('property-type'); if (is_array($property_terms) && count($property_terms)) { ?>
<div class="mkdf-grid-row">
<div class="mkdf-grid-col-3">
<select name="property_type[]" id="property_term">
<?php foreach ($property_terms as $property_term) { ?>
<option value="<?php echo esc_attr($property_term['id'])?>"><?php esc_html_e($property_term['name'],'mkdf-real-estate'); ?></option>
<label class="mkdf-select-label" for="mkdf-feature-<?php echo esc_attr($property_term['id'])?>">
<span class="mkdf-label-view"></span>
<span class="mkdf-label-text"></span>
<?php echo esc_html($property_term['name'])?>
</label>
<?php } ?>						
</select>
</div>
</div>
<?php } ?>
</div>	

#10

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.