Linking to a form with a specific pre-loaded option in a select

Hello! I am trying to set up the following results:

My home page (html) has a list of several websites. Most of the content for each website listing is in HTML, and some of it is generated through PHP/MySQL based on the website’s index and query results.

There is a “Submit a Review” link next to each website that goes to another page which contains a form. The form has a select drop-down menu to choose which website URL to review, and the options are loaded, again, through PHP/MySQL based on the website’s index and query results.

What I want is when the link from my home page opens the new page containing the form, the form automatically loads the appropriate website URL based on the link from the home page. For now, it just opens with the form displaying “Choose One” (blank) on the Website URL drop-down select.

Here’s some of the code I have on the home page:


www.samplewebsite2.com

A list of browse categories:

<?php include("dbinfo.inc.php"); mysql_connect($host,$username,$password); @mysql_select_db($database) or die( "Unable to select database");

$query=" SELECT * FROM MyListOfSites WHERE SiteID=‘1’";
$result = mysql_query($query);
$num=mysql_numrows($result);

if ($num==0) {
echo “No browse categories available.”;
} else {

$i=0;
while ($i < $num) {

$Browse1=mysql_result($result,$i,“Browse1”);
$Browse2=mysql_result($result,$i,“Browse2”);
$Browse3=mysql_result($result,$i,“Browse3”);
$Updated=mysql_result($result,$i,“Updated”);
echo "Browse Cateogory 1: $Browse1 ";
echo "Browse Cateogory 2: $Browse2 ";
echo "Browse Cateogory 3: $Browse3 ";
echo "Info Last Updated: $Updated ";
$i++;
}
}
mysql_close();
?>

www.samplewebsite2.com

A list of browse categories:

<?php include("dbinfo.inc.php"); mysql_connect($host,$username,$password); @mysql_select_db($database) or die( "Unable to select database");

$query=" SELECT * FROM MyListOfSites WHERE SiteID=‘2’";
$result = mysql_query($query);
$num=mysql_numrows($result);

if ($num==0) {
echo “No browse categories available.”;
} else {

$i=0;
while ($i < $num) {

$Browse1=mysql_result($result,$i,“Browse1”);
$Browse2=mysql_result($result,$i,“Browse2”);
$Browse3=mysql_result($result,$i,“Browse3”);
$Updated=mysql_result($result,$i,“Updated”);
echo "Browse Cateogory 1: $Browse1 ";
echo "Browse Cateogory 2: $Browse2 ";
echo "Browse Cateogory 3: $Browse3 ";
echo "Info Last Updated: $Updated ";
$i++;
}
}
mysql_close();
?>


Here’s some of the code on my Submit Review page:


Name:
Email:
Website: Choose One <?php include("dbinfo.inc.php"); mysql_connect($host,$username,$password); @mysql_select_db($database) or die( "Unable to select database"); $query=" SELECT * FROM MyListOfSites"; $result = mysql_query($query); $num=mysql_numrows($result); if ($num==0) { echo "No web sites available."; } else { $i=0; while ($i < $num) { $url=mysql_result($result,$i,"URL"); echo "$url"; $i++; } } mysql_close(); ?>
Review:

And my form processing .php (that emails me the info they submitted on the review) is pretty standard, and everything works.

My conundrum remains: How to get the URL select to show the appropriate option (correlating to the URL of the website they want to review from the home page link) when the page is first loaded.

Please help!

On the home page, you need to pass the url as a parameter to the review script, for example your links can be constructed like this:

[php]
Review www.samplewebsite1.com
[/php]

And then, in the review script, you need to modify your code where you generate options for the drop down:

[php]

$u=urldecode($_GET[“u”]);

$i=0;
while ($i < $num) {

$url=mysql_result($result,$i,“URL”);
echo “<option value=’$url’”.($u==$url?" selected":"").">$url";

$i++;
}
[/php]

[font=andale mono]@Popov: [/font]
[font=andale mono]Yay, it worked like a charm. I just had to convert the html review submission page to a .php file, and your code did exactly what I wanted. You are awesome. Thank you lots![/font]

I’m glad it worked for you.
Whenever you have any other PHP programming questions, or need help with your code - feel free to post here!

:wink:

Sponsor our Newsletter | Privacy Policy | Terms of Service