Jump to content

PHP and database retrieval with drop down box


redsent

Recommended Posts

I can't get it to use the item that is selected in the drop down box as the variable $va in the bit where it then queries the data base to retrieve only the line in the able that match the program_name with variable $va. variable $va would be the result of the drop down box.

 

Below is the code i have so far, any help would be appreciated.

 

Cheers.

 

<?php
include ('dbConn.php');

mysql_select_db($dbselect, $con);

$QuerySelects = "SELECT program_name FROM program_names";
$Query = mysql_query($QuerySelects) or die (mysql_errno() . ": " . mysql_error(). "\n");

echo '<label>Select Store:</label>';
echo '<select id="program_name"  name="program_name">';
echo '<option value="va">Select Store</option>';

while ($row = mysql_fetch_assoc($Query))
{
$va = $row['program_name'];
echo "<option value=''>$va</option>";
}
echo '</select>';



$QuerySelects1 = "SELECT * FROM offers1 WHERE end_date>CURDATE() AND program_name = '$va'";
$Query1 = mysql_query($QuerySelects1) or die (mysql_errno() . ": " . mysql_error(). "\n");



while($result=mysql_fetch_assoc($Query1)) {
include ('variables.php');
echo"
<div class='spacerbox'>
<div class='outerbox eviecodes'>
<div><div class='topbox'>
	<div class='leftbox'>
		<div class='offerimage'>
			<div class='progdiv'><a class='progname' href=".$url." target='_blank'>".$program_name."</a></div>
</div>
	</div>
	<div class='rightbox'><div class='descbox boxwidth'><h1>
		<a href=".$url." target='_blank'>".$description." at ".$program_name."</a></h1></div>
	<div class='voubox boxwidth'><h2 class='vvv'>Voucher Code:<span class='vcode'>".$code."</span ></h2></div>

</div>
</div>
<div class='linkbox boxwidthl'>
		<a href=".$url." target='_blank'>To Take Advantage of this offer at <span class='prodname'>".$program_name."</span>, click here!</a>
	</div>
<div class='expires'>
<span class='end'>Expires:</span> <span>".$dateformat."</span >
</div>
<div class='socialbox'>
{module Tell A Friend Module}
</div></div>
<div class='spacer'>
</div>
</div>
</div>
";
}
?>

change these lines here:

$va = $row['program_name'];
echo "<option value=''>$va</option>";

To the following:

$va = $row['program_name'];
echo "<option value='$va'>$va</option>";

It is the "value" of the option that is passed as contnent information, the text between the tags is simply for the end users benefit.

the name of the <select> form element is used for the key name, the value atribute for the <option> form element is used as the value of that key so $_POST['<select element name>'] == <chosen option value atribute>

 

if you set <option value=''> then the value will be an empty string.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.