Reputation: 57
Does anyone know how to get the content to render when a user selects a specific month from a dropdown menu? I feel like there's something needed with the form. And I've declared each month, so want to render the content if the month matches the dates in the database. Thoughts? Thanks!
<div id="content">
<h1>Search by Album, Artist, or Genre</h1>
<form method="GET" action="" >
<select>
<option value="selectmonth">Select a month</option>
<option value="July 2014" name="July">July 2014</option>
<option value="August 2014" name="August">August 2014</option>
<option value="September 2014" name="September">September 2014</option>
</select>
</form>
<br />
<?php
$conn = new COM("ADODB.Connection") or die("Cannot start ADO");
$connString= "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=e:\\FinalProject.mdb";
//creates the connection object and define the connection string
$month1 = $_GET ['July'];
$month2 = $_GET ['August'];
$month2 = $_GET ['September'];
//update
$conn->Open($connString);
$selectCommand="SELECT * FROM products WHERE relasedate LIKE '$released'";
if(isset($_GET['July','August','September'])){
$rs = $conn->Execute($selectCommand);
//execute search when user selects month
if (!$rs->EOF){
print "<h2>New releases for '<b>$released</b>':</h2>";
} //search results header
if ($rs->EOF){
print "No results found.<br /><br />";
}else{
while (!$rs->EOF){
$selectCommand=$rs->Fields("ItemID");
$artist=$rs->Fields("artist");
$album=$rs->Fields("album");
$genre=$rs->Fields("Genre");
$desc=$rs->Fields("itemdesc");
$recordl=$rs->Fields("recordlabel");
$released=$rs->Fields("releasedate");
$images=$rs->Fields("photos");
echo "
<div><img src=$images></div>
<div><b>Artist</b>: $artist <br />
<b>Album</b>: $album <br />
<b>Record Label</b>: $recordl <br />
<b>Release Date</b>: $released <br />
<b>Genre</b>: $genre <br />
<b>Description</b>: $desc <br />
</div>";
$rs->movenext();
} //while loop to render results
} //end if statement for null results
$rs->Close;
} //close connection
?>
</div>
Upvotes: 0
Views: 1017
Reputation: 1590
Make a div in the page which we will call contentDiv
. Secondly, use AJAX to update the div:
<script>
function loadContent(selectedVal) {
var xmlhttp;
if (window.XMLHttpRequest) {
// code for IE7+, Firefox, Chrome, Opera, Safari
xmlhttp=new XMLHttpRequest();
} else {
// code for IE6, IE5
xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
}
xmlhttp.onreadystatechange=function() {
if (xmlhttp.readyState==4 && xmlhttp.status==200) {
document.getElementById("contentDiv").innerHTML=xmlhttp.responseText;
}
}
xmlhttp.open("GET","getInfoFromDatabase.php?selected=" + selectedVal,true);
xmlhttp.send();
}
</script>
You would have to add onchange="loadContent(this.value)"
to your select box to get its value.
You would then have getInfoFromDatabase.php return whatever you need based on the $_GET['selected']
value.
Upvotes: 1