osclass Cities dropdown based on Region Select - php

Im using osclass for a local classifieds website and im facing the following problem. I need to import 12 regions and 7000 cities/villages.
In the main.php im using a horizontal search bar with fields search text, categories (dropdown), Regions (dropdown), City (dropdown), Max price(text) and min Price (text)
For the Regions and Cities im using the code in inc.search.php
<?php $aRegions = Region :: newInstance()->listAll();?>
<?php if (count($aRegions) > 0) {?>
<select name="sRegion" id="sRegion">
<option value="">Select a Region</option>
<?php foreach ($aRegions as $region) {?>
<option value="<?php echo $region['s_name'];?>"><?php echo $region['s_name'];?> </option>
<?php } ?>
</select>
<?php } ?>
<?php $aCities = City::newInstance()->listAll(); ?>
<?php if(count($aCities) > 0 ) { ?>
<select name="sCity" id="sCity">
<option value="">Select a city</option>
<?php foreach($aCities as $City) { ?>
<option value="<?php echo $City['s_name'] ; ?>"><?php echo $City['s_name'] ; ?></option>
<?php }?>
</select>
<?php }?>
The problem is that the above code brings all cities when page loads and does not check what region is selected first. That means that the city dropdown will be filled with 7000 cities/villages when page loads.
I tried to remove lines
<?php foreach($aCities as $City) { ?>
<option value="<?php echo $City['s_name'] ; ?>"><?php echo $City['s_name'] ; ?></option>
<?php }?>
so when page loads, the city dropdown is empty but i dont know how to fill the dropdown with cities depend on region select.

The solution to how to use region/city in search form is described here http://forums.osclass.org/jobs/cities-dropdown-based-on-region-select/

Related

how to keep drop down selected values after pressing submit button in php?

enter image description hereI am using a dropdown list to show values in data tables. it's working but after press search button the dropdwon list clears.
<select name="staff" required>
<option value="">Select Staff</option>
<?php
$query_subject = mysql_query("SELECT * from staffdet");
while($row_subject = mysql_fetch_array($query_subject)) {
?>
<option value="<?php echo $row_subject['staff_code'];?>"><?php echo $row_subject['staff_code']."-".$row_subject['staff_name'];?></option>
<?php } ?>
</select>
How to keep selected dropdown list values?
IF you are submitting a form on same page with POST method then below code will solve your problem
<select name="staff" required>
<option value="">Select Staff</option>
<?php
$query_subject = mysql_query("SELECT * from staffdet");
while($row_subject = mysql_fetch_array($query_subject)) {
?>
<option value="<?php echo $row_subject['staff_code'];?>" <?php if(!empty($_POST['staff']) && $_POST['staff']==$row_subject['staff_code']){echo 'selected="selected"';}?>>
<?php echo $row_subject['staff_code']."-".$row_subject['staff_name'];?>
</option>
<?php } ?>

Php string replace of values

In opencart shop i have a product limit in category page, for example the default number of products per page.I setet up the maximul number to be 1000, but i wanna strig replace that number to "ALL".
Belo is the code for the string. <?php echo $limits['text']; ?>
I wanna string replace $limits['text'] for the value 1000 to be ALL
<select onchange="location = this.value;">
<?php foreach ($limits as $limits) { ?>
<?php if ($limits['value'] == $limit) { ?>
<option value="<?php echo $limits['href']; ?>" selected="selected"><?php echo $limits['text']; ?></option>
<?php } else { ?>
<option value="<?php echo $limits['href']; ?>"><?php echo str_replace('1000', 'ALL', $limits['text']); ?></option>
<?php } ?>
<?php } ?>
</select>
This works but in the link of the page it sould be like this
/index.php?route=product/category&path=142#/sort=p.sort_order/order=ASC/limit=1000
but is like this
/index.php?route=product/category&path=142#/sort=p.sort_order/order=ASC/limit=All
In inspect element the code is generated corectly
<select>
<option value="http://diamanti.teamweb.ro/index.php?route=product/category&path=142&limit=30" selected="selected">30</option>
<option value="http://diamanti.teamweb.ro/index.php?route=product/category&path=142&limit=90">90</option>
<option value="http://diamanti.teamweb.ro/index.php?route=product/category&path=142&limit=1000">All</option>
</select>
But when i click ALL , the link modifiecs not with the "value" But with the text...

Display dropdown box with checkbox

<select name="city[]" id="CitySD" class="select required" multiple>
<option value=""><?php echo $this->Lang["SEL_COUNTRY"]; ?></option>
<?php
foreach ($this->all_city_list as $c)
{
?>
<option <?php
if (isset($this->userPost['city']))
{
if ($c->city_id == $this->userPost['city'])
{
?> selected <?php
}
}
?> title="<?php echo $c->city_name; ?>"value="<?php echo $c->city_id; ?>">
<?php echo $c->city_name; ?>
</option>
<?php } ?>
</select>
Above is my city drop down field in registration page,if user select country means then only the city filed gets active and its display city based on user selection country.
I want to display cities in the city drop down with individual checkbox option for all cities and select all option check box,the user can click select all means it will select all cities and deselect means it will deselect all cities and user can also select random cities.
please anyone can help me!

PHP & HTML : how to create dynamic drop down list

I have a little problem.
I'm searching the internet now for quite some time to find a proper solution but I was not successful so far.
This is what I want :
First, I choose Category
Then, in second selection contain all the store result from category selection.
this is my first drop down list which is contain Category :
<select name="category" class="form-control" id="select1">
<option value="-1"> - Choose One -</option>
<?php
$StoreCategoriesAPIAccessor = new StoreCategoriesAPIService(GuzzleClient::getClient());
$stores = $StoreCategoriesAPIAccessor->getStoreCategories();
foreach ($stores as $store):
?>
<option value="<?php echo $store->getStoreCategoryId(); ?>"><?php echo $store->getCategory(); ?></option>
<?php endforeach; ?>
</select>
this is my second drop down list :
<select name="category" class="form-control" id="select2">
<option value="-1"> - Choose One -</option>
<?php
$StoreAPIAccessor = new StoreAPIService(GuzzleClient::getClient());
$stores = $StoreAPIAccessor->getStores();
foreach ($stores as $store):
?>
<option value="<?php echo $store->getStoreId(); ?>"><?php echo $store->getStoreName(); ?></option>
<?php endforeach; ?>
</select>
Anyone know how to implement dynamic drop down list for this case ?
Well first of all I'd like to ask that you separate business logic from view logic as much as possible, so I will do that in this answer.
Secondly, the 2nd dropdown box logic that you have does not contain anything that would retrieve stores for a given category, I will therefore make some assumptions and you can adjust based on that.
<?php
$StoreCategoriesAPIAccessor = new StoreCategoriesAPIService(GuzzleClient::getClient());
$categories = $StoreCategoriesAPIAccessor->getStoreCategories();
if (!empty($_GET['category'])) {
$category_id = $_GET['category'];
$StoreAPIAccessor = new StoreAPIService(GuzzleClient::getClient());
$stores = $StoreAPIAccessor->getStores($category_id); // Assumption, the call to getStores() accepts category_id as a parameter
} else { // Optional as you don't need to declare variables in PHP, but its better practice to do so
$category_id = null;
$stores = array();
}
?>
<select id="select_category" name="category" class="form-control" onchange="window.location='?category=' + this.value">
<option value="">- Choose One -</option>
<?php foreach ($categories as $category): ?>
<option value="<?php echo $category->getStoreCategoryId() ?>"><?php echo $category->getCategory() ?></option>
<?php endforeach ?>
</select>
<select id="select_store" name="store" class="form-control"<?php echo $category_id == null ? " disabled='disabled'" : "">
<option value="">- Choose One -</option>
<?php foreach ($stores as $store): ?>
<option value="<?php echo $store->getStoreId() ?>"><?php echo $store->getStoreName() ?></option>
<?php endforeach ?>
</select>

default select value from mysql query in dropdown box

You guys have been patient with me and very helpful so far, so I'll try another one. I have looked around on here and tried many different options of select="selected" and I just can't get the code right or something, a simple fix I'm sure for you guys. What I'm trying to do is have a drop down list that is populated from a table of countries, default to the United States. Here is the code:
<select name="cnt" id="">
<option value="">Select</option>
<?php
$rescnt=mysql_query("select * from `country` ORDER by cnt_name ASC");
while($rowcnt=mysql_fetch_array($rescnt)) {
?>
<option value="<?php echo $rowcnt['cnt_id']; ?>"><?php echo $rowcnt['cnt_name']; ?></option>
<?php } ?>
</select>
Assuming the cnt_id for the United States is 'US', the option line should be:
<option value='<?php echo $rowcnt['cnt_id']; ?>'<?php if($rowcnt['cnt_id']=='US') echo ' selected'; ?>><?php echo...

Categories