| | |
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 |
action address advanced ajax apache api array auto autoincrement basics beginner broken cakephp class cms code codingproblem combobox cron curl database date datepart display domain dynamic email error errorlog file folder form format forms function functions google head href htaccess html image include includingmysecondfileinthechain interactive ip javascript job joomla js limit link load login malfunctioning masterthesis menu multiple mysql nodes oop outofmemmory paging password paypal pdf php popup problem procedure query ram random reference script search server sessions smarty source space sql stored syntax system table traffic tutorial unicode unset up-to-date upload url validation variable video web webapplications websitecontactform youtube





