All values received from a database will be a string data type. However the PHP lexer, will automatically evaluate numeric string comparisons as an integer or float value.
When a string is evaluated in a numeric context, the resulting value and type are determined as follows.
If the string does not contain any of the characters '.', 'e', or 'E'
and the numeric value fits into integer type limits (as defined by
PHP_INT_MAX), the string will be evaluated as an integer. In all other
cases it will be evaluated as a float. [sic]
This allows for "10" > 2 and "10" > "2" to be evaluated correctly and without the need of typecasting or using intval. [Example]
The main reason for your issue is caused by not using a range to limit the min and max prices to select. As a result you will have multiple values set as selected and the browser will only show the first as the selected option. To circumvent the multiple selected options issue, you would need to use a conditional range like $price >= $min && $price <= $max.
To reduce the repetitive html, you can use an array as your limit definitions, and iterate over the array to draw out the html.
<?php $limits = [
'-100000' => [
'min' => null,
'max' => 100000
],
'100000' => [
'min' => 100001,
'max' => 150000
],
//...
'350000' => [
'min' => 300001,
'max' => 350000
],
'400000' => [
'min' => 350001,
'max' => 400000,
],
//...
'1000000' => [
'min' => 900001,
'max' => 1000000,
],
'1000000+' => [
'min' => 1000001,
'max' => null,
],
]; ?>
<!-- ....... -->
<label for="maxprice">Max Price</label>
<select id="maxprice" name="maxprice">
<?php
$price = $row['maxprice'];
foreach ($limits as $amount => $limit) {
$min = $limit['min'];
$max = $limit['max'];
?>
<option <?php echo((null === $min || $price >= $min) && (null === $max || $price <= $max) ? 'selected' : ''); ?>><?php echo $amount; ?></option>
<?php } ?>
</select>
Alternatively you can also achieve your desired results by using range(100000, 1000000, 50000); to generate your values and use conditions to detect the first < and last > entries, or $price >= $amount - 49999 && $price <= $amount for all other values.
$amounts = range(100000, 1000000, 50000);
end($amounts);
$last = key($amounts);
//alternatively use $last = count($amounts) - 1;
<label for="maxprice">Max Price</label>
<select id="maxprice" name="maxprice">
<?php foreach ($amounts as $i => $amount) {
if (0 === $i) { ?>
<option<?php echo($row['maxprice'] < $amount ? ' selected' : ''); ?>><?php echo '-' . $amount; ?></option>
<?php } ?>
<option<?php echo($row['maxprice'] >= $amount - 49999 && $row['maxprice'] <= $amount ? ' selected' : ''); ?>><?php echo $amount; ?></option>
<?php if($last === $i) { ?>
<option<?php echo($row['maxprice'] > $amount ? ' selected' : ''); ?>><?php echo $amount . '+'; ?></option>
<?php } ?>
<?php } ?>
</select>
Results
<label for="maxprice">Max Price (20)</label>
<select id="maxprice" name="maxprice">
<option selected>-100000</option>
<option>100000</option>
<option>150000</option>
<option>200000</option>
<option>250000</option>
<option>300000</option>
<option>350000</option>
<option>400000</option>
<option>450000</option>
<option>500000</option>
<option>550000</option>
<option>600000</option>
<option>650000</option>
<option>700000</option>
<option>750000</option>
<option>800000</option>
<option>850000</option>
<option>900000</option>
<option>950000</option>
<option>1000000</option>
<option>1000000+</option>
</select>
<label for="maxprice">Max Price (340000)</label>
<select id="maxprice" name="maxprice">
<option>-100000</option>
<option>100000</option>
<option>150000</option>
<option>200000</option>
<option>250000</option>
<option>300000</option>
<option selected>350000</option>
<option>400000</option>
<option>450000</option>
<option>500000</option>
<option>550000</option>
<option>600000</option>
<option>650000</option>
<option>700000</option>
<option>750000</option>
<option>800000</option>
<option>850000</option>
<option>900000</option>
<option>950000</option>
<option>1000000</option>
<option>1000000+</option>
</select>
<label for="maxprice">Max Price (360000)</label>
<select id="maxprice" name="maxprice">
<option>-100000</option>
<option>100000</option>
<option>150000</option>
<option>200000</option>
<option>250000</option>
<option>300000</option>
<option>350000</option>
<option selected>400000</option>
<option>450000</option>
<option>500000</option>
<option>550000</option>
<option>600000</option>
<option>650000</option>
<option>700000</option>
<option>750000</option>
<option>800000</option>
<option>850000</option>
<option>900000</option>
<option>950000</option>
<option>1000000</option>
<option>1000000+</option>
</select>
<label for="maxprice">Max Price (1000000)</label>
<select id="maxprice" name="maxprice">
<option>-100000</option>
<option>100000</option>
<option>150000</option>
<option>200000</option>
<option>250000</option>
<option>300000</option>
<option>350000</option>
<option>400000</option>
<option>450000</option>
<option>500000</option>
<option>550000</option>
<option>600000</option>
<option>650000</option>
<option>700000</option>
<option>750000</option>
<option>800000</option>
<option>850000</option>
<option>900000</option>
<option>950000</option>
<option selected>1000000</option>
<option>1000000+</option>
</select>
<label for="maxprice">Max Price (1500000)</label>
<select id="maxprice" name="maxprice">
<option>-100000</option>
<option>100000</option>
<option>150000</option>
<option>200000</option>
<option>250000</option>
<option>300000</option>
<option>350000</option>
<option>400000</option>
<option>450000</option>
<option>500000</option>
<option>550000</option>
<option>600000</option>
<option>650000</option>
<option>700000</option>
<option>750000</option>
<option>800000</option>
<option>850000</option>
<option>900000</option>
<option>950000</option>
<option>1000000</option>
<option selected>1000000+</option>
</select>
SELECTED<option <?phpvalue=""attribute so you know what was selected later when the PHP has to process the forms data