bigbenbuilders Posted September 16, 2009 Share Posted September 16, 2009 Hi guys here is the code that I am using for a search of the database which produces the results perfect. What I need to know is how to implement a drop down list or jump list that say for example produces $Scholarship_group list and when selected it only selects those particular rows. But still need the search button. Guess what I am trying to say if someone want to display everything that is fine but then have a drop down to display certain categories? Hope this makes sense. <form name="form" action="<?php echo $PHP_SELF ?>" method="get"> <input type="text" name="q" /> <input type="submit" name="Submit" value="Search" /> </form> <?php // Get the search variable from URL $var = @$_GET['q'] ; $trimmed = trim($var); //trim whitespace from the stored variable // rows to return $limit=10; // check for an empty string and display a message. if ($trimmed == "") { echo "<p>Please enter a search...</p>"; exit; } // check for a search parameter mysql_connect("","",""); //(host, username, password) mysql_select_db("") or die("Unable to select database"); $query = "select * from financial where Name like \"%$trimmed%\" order by id"; $numresults=mysql_query($query); $numrows=mysql_num_rows($numresults); $s = $_GET['s'] ; if ($numrows == 0) { echo "<h4>Results</h4>"; echo "<p>Sorry, your search: "" . $trimmed . "" returned zero results</p>"; } if (empty($s)) { $s=0; } $query .= " limit $s,$limit"; $result = mysql_query($query) or die("Couldn't execute query"); echo "<p>You searched for: "" . $var . ""</p>"; $count = 1 + $s; while ($row= mysql_fetch_array($result)) { $title = $row["Name"]; $Scholarship_group = $row["Scholarship_group"]; $Selection_Criterion = $row["Selection_Criterion"]; $Application_Required = $row["Application_Required"]; $Awarded_Committee = $row["Awarded_Committee"]; $Renewable = $row["Renewable"]; $Need_Based = $row["Need_Based"]; $Tuition_Restricted = $row["Tuition_Restricted"]; $GPA_Required = $row["GPA_Required"]; $Class_Level = $row["Class_Level"]; $major_minor_requirement = $row["major_minor_requirement"]; $extracurricular_requirement = $row["extracurricular_requirement"]; $ACT_Score = $row["ACT_Score"]; $SAT_Score = $row["SAT_Score"]; $Religion = $row["Religion"]; $gender = $row["gender"]; $geographic_region = $row["geographic_region"]; $zipcode_range = $row["zipcode_range"]; $Diversity = $row["Diversity"]; echo "$count.) <strong>$title</strong> <br><br> " ; ?> <span class="style3"> <? echo "<strong>Scholarship Info:--></strong>"; echo " "; if(empty($row['Scholarship_group'])){ //empty() returned true : so there is nothing echo 'Scholarship group - None'; }else{ //empty() returned false so it is NOT true that there is nothing //so we can print it out: echo "Scholarship Group - $Scholarship_group"; } echo " | "; if(empty($row['Selection_Criterion'])){ //empty() returned true : so there is nothing echo 'Selection Criterion - None'; }else{ //empty() returned false so it is NOT true that there is nothing //so we can print it out: echo "Selection Criterion - $Selection_Criterion"; } echo " | "; if(empty($row['Application_Required'])){ //empty() returned true : so there is nothing echo 'Application Required - No'; }else{ //empty() returned false so it is NOT true that there is nothing //so we can print it out: echo "Application Required - $Application_Required"; } echo " | "; if(empty($row['Awarded_Committee'])){ //empty() returned true : so there is nothing echo 'Awarded Committee - No'; }else{ //empty() returned false so it is NOT true that there is nothing //so we can print it out: echo "Awarded Committee - $Awarded_Committee"; } echo " | "; if(empty($row['Renewable'])){ //empty() returned true : so there is nothing echo 'Renewable - No'; }else{ //empty() returned false so it is NOT true that there is nothing //so we can print it out: echo "Renewable - $Renewable"; } echo "<br><br>"; echo "<strong>Award Criteria:--> </strong>"; if(empty($row['Need_Based'])){ //empty() returned true : so there is nothing echo 'Need_Based - No'; }else{ //empty() returned false so it is NOT true that there is nothing //so we can print it out: echo "Need Based - $Need_Based"; } echo " | "; if(empty($row['Need_Based'])){ //empty() returned true : so there is nothing echo 'Tuition Restricted - No'; }else{ //empty() returned false so it is NOT true that there is nothing //so we can print it out: echo "Tuition Restricted - $Tuition_Restricted"; } echo " | "; if(empty($row['Need_Based'])){ //empty() returned true : so there is nothing echo 'GPA Required - No'; }else{ //empty() returned false so it is NOT true that there is nothing //so we can print it out: echo "Minimum GPA Required - $GPA_Required"; } echo " | "; if(empty($row['Class_Level'])){ //empty() returned true : so there is nothing echo 'Class Level - No'; }else{ //empty() returned false so it is NOT true that there is nothing //so we can print it out: echo "Class Level - $Class_Level"; } echo " | "; if(empty($row['major_minor_requirement'])){ //empty() returned true : so there is nothing echo 'major/minor academic requirement - No'; }else{ //empty() returned false so it is NOT true that there is nothing //so we can print it out: echo "major/minor academic requirement - $major_minor_requirement"; } echo " | "; if(empty($row['extracurricular_requirement'])){ //empty() returned true : so there is nothing echo 'extracurricular requirement - No'; }else{ //empty() returned false so it is NOT true that there is nothing //so we can print it out: echo "extracurricular requirement - $extracurricular_requirement"; } echo " | "; if(empty($row['ACT_Score'])){ //empty() returned true : so there is nothing echo 'ACT Score - No'; }else{ //empty() returned false so it is NOT true that there is nothing //so we can print it out: echo "ACT Score - $ACT_Score"; } echo " | "; if(empty($row['SAT_Score'])){ //empty() returned true : so there is nothing echo 'SAT Score - No'; }else{ //empty() returned false so it is NOT true that there is nothing //so we can print it out: echo "SAT Score - $SAT_Score"; } echo "<br><br>"; echo "<strong>Personal Info:--> </strong>"; if(empty($row['Religion'])){ //empty() returned true : so there is nothing echo 'Religion - No'; }else{ //empty() returned false so it is NOT true that there is nothing //so we can print it out: echo "Religion - $Religion"; } echo " | "; if(empty($row['gender'])){ //empty() returned true : so there is nothing echo 'gender - No'; }else{ //empty() returned false so it is NOT true that there is nothing //so we can print it out: echo "gender - $gender"; } echo " | "; if(empty($row['geographic_region'])){ //empty() returned true : so there is nothing echo 'geographic region - No'; }else{ //empty() returned false so it is NOT true that there is nothing //so we can print it out: echo "geographic region - $geographic_region"; } echo " | "; if(empty($row['zipcode_range'])){ //empty() returned true : so there is nothing echo 'zipcode range - No'; }else{ //empty() returned false so it is NOT true that there is nothing //so we can print it out: echo "zipcode range - $zipcode_range"; } echo " | "; if(empty($row['Diversity'])){ //empty() returned true : so there is nothing echo 'Diversity - No'; }else{ //empty() returned false so it is NOT true that there is nothing //so we can print it out: echo "Diversity - $Diversity"; } ?></span> <? echo "<br><br>"; $count++ ; } $currPage = (($s/$limit) + 1); echo "<br />"; if ($s>=1) { // bypass PREV link if s is 0 $prevs=($s-$limit); print " <a href=\"$PHP_SELF?s=$prevs&q=$var\"><< Prev 10</a>  "; } $pages=intval($numrows/$limit); if ($numrows%$limit) { $pages++; } if (!((($s+$limit)/$limit)==$pages) && $pages!=1) { $news=$s+$limit; echo " <a href=\"$PHP_SELF?s=$news&q=$var\">Next 10 >></a>"; } $a = $s + ($limit) ; if ($a > $numrows) { $a = $numrows ; } $b = $s + 1 ; echo "<p>Showing results $b to $a of $numrows</p>"; ?> Quote Link to comment Share on other sites More sharing options...
bigbenbuilders Posted September 16, 2009 Author Share Posted September 16, 2009 okay this populates the drop down but how would I have it display the categories on the page without having to click a submit button...kind of like a jump menu? <?php require_once('../Connections/cuaa_scholarships.php'); ?> <?php if (!function_exists("GetSQLValueString")) { function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "") { $theValue = get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue; $theValue = function_exists("mysql_real_escape_string") ? mysql_real_escape_string($theValue) : mysql_escape_string($theValue); switch ($theType) { case "text": $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL"; break; case "long": case "int": $theValue = ($theValue != "") ? intval($theValue) : "NULL"; break; case "double": $theValue = ($theValue != "") ? "'" . doubleval($theValue) . "'" : "NULL"; break; case "date": $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL"; break; case "defined": $theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue; break; } return $theValue; } } mysql_select_db($database_cuaa_scholarships, $cuaa_scholarships); $query_Recordset1 = "SELECT DISTINCT financial.Scholarship_group FROM financial order by financial.Scholarship_group ASC"; $Recordset1 = mysql_query($query_Recordset1, $cuaa_scholarships) or die(mysql_error()); $row_Recordset1 = mysql_fetch_assoc($Recordset1); $totalRows_Recordset1 = mysql_num_rows($Recordset1); ?><form name="form1" method="post" action=""> <label for="select"></label> <select name="select" id="select"> <?php do { ?> <option value="<?php echo $row_Recordset1['Scholarship_group']?>"><?php echo $row_Recordset1['Scholarship_group']?></option> <?php } while ($row_Recordset1 = mysql_fetch_assoc($Recordset1)); $rows = mysql_num_rows($Recordset1); if($rows > 0) { mysql_data_seek($Recordset1, 0); $row_Recordset1 = mysql_fetch_assoc($Recordset1); } ?> </select> </form> <?php mysql_free_result($Recordset1); ?> Quote Link to comment 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.