redsent Posted March 19, 2012 Share Posted March 19, 2012 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> "; } ?> Quote Link to comment https://forums.phpfreaks.com/topic/259246-php-and-database-retrieval-with-drop-down-box/ Share on other sites More sharing options...
Muddy_Funster Posted March 19, 2012 Share Posted March 19, 2012 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. Quote Link to comment https://forums.phpfreaks.com/topic/259246-php-and-database-retrieval-with-drop-down-box/#findComment-1328972 Share on other sites More sharing options...
redsent Posted March 19, 2012 Author Share Posted March 19, 2012 does that set the variable $va when the drop down box is picked so it can be used later on? Cheers. Quote Link to comment https://forums.phpfreaks.com/topic/259246-php-and-database-retrieval-with-drop-down-box/#findComment-1329037 Share on other sites More sharing options...
dmikester1 Posted March 19, 2012 Share Posted March 19, 2012 I believe the 'value' value is optional for the <option> tag. I believe it gets automatically set to what is between the <option> tags when the data is posted. Mike Quote Link to comment https://forums.phpfreaks.com/topic/259246-php-and-database-retrieval-with-drop-down-box/#findComment-1329039 Share on other sites More sharing options...
Muddy_Funster Posted March 19, 2012 Share Posted March 19, 2012 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. Quote Link to comment https://forums.phpfreaks.com/topic/259246-php-and-database-retrieval-with-drop-down-box/#findComment-1329050 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.