Jump to content

[SOLVED] select single result not showing


richrock

Recommended Posts

Hi,  having a really strange problem with a select result...

 

here's the code:

 

<select name="city" id='inputtext' onchange="this.form.submit();" class="inputbox">
        <option value="">-- Select City --</option>
        <?php
            while ($row_city=mysql_fetch_array($rcity)) {
            
            echo '<option value="'.$row_city['city'].'">'.$row_city['city'].'</option>';
            //echo '<option value="'.$row_city['city'].'"'.($row_city['city']==$city ? ' selected' : '').'>'.$row_city['city'].'</option>';
            }
        ?>
		</select>

 

What happens is if there is more than one result in the mysql query, the select populates with all the results.  If there is only one result in the mysql query, then it doesn't show at all.  I have checked this as I am using mysql_num_rows and have tested it.  I can't figure why this is.  Any ideas?

 

And here's the mysql bit :

 

$getcity = "SELECT DISTINCT city FROM yearbook ";
if ($src_country == !NULL) {
    $getcity .= "WHERE country = '".$src_country."' ";
}
$getcity .= "ORDER BY city ASC";
$rcity = mysql_query($getcity) or die(mysql_errno() . mysql_error());
$row_city = mysql_fetch_assoc($rcity);
$tRows_city = mysql_num_rows($rcity);

 

The $src_country bit is for the select to filter the results if someone has selected a country, and I'm doing the same on the country select if they select a city first...

Link to comment
https://forums.phpfreaks.com/topic/153997-solved-select-single-result-not-showing/
Share on other sites

Okay, it works fine, but I've discovered a new issue (ah the joys of programming :P)

 

I have in the DB the cities (city), and they don't always have a city allocated, so the entry is empty.  The select now defaults to the blank entry, instead of the --Select City-- option...

 

so I get something like this in the output:

 

<select>
<option value = "">--Select City--</option>
<option value = "" selected></option>
<option value = "London">London</option>
<option value = "Manchester">Manchester</option>
(etc...)
</select>

 

But it should either be --Select City-- or the city I have chosen...  I can't remove the blank entries, but don't wnat them selected when I choose my country.

 

TIA,

 

Richard

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.