<?
$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

[B]echo "<option label=\"$nt[product_name]\" value=\"$nt[url]\">$nt[product_name]</option>";[/B]
/* Option values are added by looping through the array */
}
echo "</select>";// Closing of list box
?>

In the drop down above I have the following options showing: Day You Were Born, Day You Were Married, Day You Were Christened. I want to select the correct option in the list according to the page the drop down appears on i.e I want the drop down to show 'Day You Were Marriedat the top of the list when the Day You Were Married page is displayed, Day You Were Born at the top of the list when the day you were born page is displayed and 'Day You Were Christened' at the top when the day you were christened page is displayed. So really what I am after is someone who can help with reordering the results according to the page it is on.

Can Anybody help????

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:

$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?

This article has been dead for over six months. Start a new discussion instead.