Populate a dropdown

Hi,

I have a search form to which I’m trying to add another drop down.

I have a table called “properties” which has a column titled “address_city” which I’m trying to pull results from. I’ve been playing with what I have below but I just cant get it to work. Please could someone advise me where I’m going wrong?

Thanks in advance…

[php] <?php echo $PL_LANG['property_choose']; ?>
<?php
$sql = “SELECT DISTINCT address_city FROM “.$TABLES[‘properties’].” ORDER BY title;”;
{
?>
<?php echo $row['address_city'];?>
<?php
}
?>[/php]

For starters, there is no code to actually execute your query.

Sorry,

How about this…Please forgive me, I’m not very good!

[php]<?php
$sql = “SELECT DISTINCT address_city FROM “.$TABLES[‘properties’].” ORDER BY title;”;
$sql_result = mysql_query ($sql, $connection ) or die ('request “Could not execute SQL query” '.$sql);

				while ($row = mysql_fetch_assoc($sql_result)) {
					?>
					<option value="<?php echo $row['address_city'];?>"><?php echo $row['address_city'];?></option>
					<?php
				}
				?>[/php]

Your using obsolete mysql code. You need to use PDO or Mysqli. There is a link in my signature for a PDO database. The code in there should help you out.

Kevin,

Thank you for taking the time to answer.

My problem is, I have to go with what I have on this occasion.

That is not a good response. If the code did not work, would you still use it because of time constraints? Think of it as not functional at this point. Your stakeholders will understand if something corrupts their site, taking the time to fix it.

Well, not to start a discussion off topic, but, many times I have huge sites that need minor changes
which are still written in older code. One recent one was a horrible ASP site with 15 year old code. Yuk!

Anyways, in my humble opinion, moving up from the now obsolete mysql code to the “improved” version
of mysqli code is very very easy to do. GJB, I think that might be the easiest update path for you. Very
few minor changes to go from mysql to mysqli. Moving to PDO is easy, but, will take much more time to
make the needed changes.

Now, with that said… You showed us one small part of you code that populates just the OPTIONS for the
SELECT drop-down. You must place your info into the code also. Perhaps you are not
using it in this format…

… All of your PHP code you showed to us…

Without seeing more of your select code, I will assume that you forgot those tags… Hope that helps!

Sponsor our Newsletter | Privacy Policy | Terms of Service