| | |
PHP Drop down ordering
Please support our PHP advertiser: PostgreSQL or MySQL? Compare and contrast the two most popular open source databases
![]() |
•
•
Join Date: Feb 2008
Posts: 20
Reputation:
Solved Threads: 0
<?
$username="*************";
$password="***************";
$database="****************";
mysql_connect("***************",$username,$password);
@mysql_select_db($database) or die( "Unable to select database");
$query="SELECT product_name, url FROM product WHERE product_name like 'Day You Were%' group by product_name order by product_name";
echo "<form action=\"https://www.paypal.com/cgi-bin/webscr\" target=\"paypal\" name=\"mygallery\" method=\"post\">";
/* You can add order by clause to the sql statement if the names are to be displayed in alphabetical order */
$result = mysql_query ($query);
echo "<font color=\"#FF0000\">1.</font> Select The Gift You Would Like:<br><select name=\"gift\" onChange=\"go()\">";
// printing the list box select command
while($nt=mysql_fetch_array($result)){//Array or records stored in $nt
echo "<option label=\"$nt[product_name]\" value=\"$nt[url]\">$nt[product_name]</option>";
/* Option values are added by looping through the array */
}
echo "</select>";// Closing of list box
?>Can Anybody help????
Last edited by myth3_16; Feb 9th, 2008 at 3:29 pm.
Hi there,
I assume you want to reorder the list just because you don't know of a better method of pre-selecting an option, right? If that's so I suggest using "selected" instead:
Does this solve your problem?
I assume you want to reorder the list just because you don't know of a better method of pre-selecting an option, right? If that's so I suggest using "selected" instead:
php Syntax (Toggle Plain Text)
$pageTitle = 'Day You Were Married'; // this is for testing, I expect this variable to be filled somewhere else in your code $preSelect[$pageTitle] = ' selected'; // $preSelect was an empty array, now it has just one item. I use this trick for pre-selecting options ... while ... printf('<option label="%s" value="%s"%s>%s</option>', $nt['product_name'], $nt['url'], $preSelect[ $nt['product_name'] ], $nt['product_name']);
Does this solve your problem?
Petr 'PePa' Pavel
The more information you give the more relevant answer you get.
Please consider using "Add to ... Reputation" and mark your thread as Solved if you found what you were looking for. By giving feedback you help others.
The more information you give the more relevant answer you get.
Please consider using "Add to ... Reputation" and mark your thread as Solved if you found what you were looking for. By giving feedback you help others.
![]() |
Similar Threads
- Move Javascript Variable to PHP (JavaScript / DHTML / AJAX)
- help with hjt and vx2/urllogic (split from http://www.daniweb.com/techtalkforums/showthread.php?t=18540&page=1&pp=15) (Viruses, Spyware and other Nasties)
Other Threads in the PHP Forum
- Previous Thread: checkbox output
- Next Thread: Using Code 5 System to create forms...I got 3 problems
| Thread Tools | Search this Thread |
apache api array basic beginner binary broken cache cakephp checkbox class cms code computing confirm cron curl customizableitems database date delete display dynamic echo email error external file files filter folder form forms forum function functions gc_maxlifetime google headmethod host howtowriteathesis href htaccess html iframe image include insert ip javascript joomla limit link login mail malfunction memmory memory menu mlm multiple mysql navigation oop parsing paypal pdf php phpmysql problem query question radio random recursion remote script search select server sessions sms snippet source space sql syntax system table thesishelp trouble tutorial update upload url validator variable video web youtube





