/* function searchresults($val1, $val2, $val3, $val4){ // Search the directory for the search terms provided $hostname = "mysql.ece.cmu.edu"; $database = "travmgmt"; $username = "textrav"; $password = "tExt44v"; $news = mysql_pconnect($hostname, $username, $password) or die(mysql_error()); mysql_select_db($database) or die(mysql_error()); // This block sets up the variables used in the query. Each one adds an AND WHERE style // clause to the query based on what was entered in the forms. // FUTURE: Set it up so people can choose AND / OR / NOT if(strcmp($val1,'')==0){ $value1 = ''; }else{ $value1 = " AND `people_firstname` LIKE '%$val1%' ";}; if(strcmp($val2,'')==0){ $value2 = ''; }else{ $value2 = " AND `people_lastname` LIKE '%$val2%' ";}; if(strcmp($val3,'')==0){ $value3 = ''; }else{ $value3 = " AND `people_title` LIKE '%$val3%' ";}; if(strcmp($val4,'')==0){ $value4 = ''; }else{ $value4 = " AND `people_keywords` LIKE '%$val4%'";}; // This takes care of the problem of all records being shown in event of no search terms being entered if( strcmp($value1,'')==0 && strcmp($value2,'')==0 && strcmp($value3,'')==0 && strcmp($value4,'')==0 ){ $limit = 0; // If nothing was entered, set the limit to zero; }else{ $limit = 65000; // otherwise show what was found } // Set the query $allQ = mysql_query("SELECT * FROM `dir_people` where people_status LIKE 'active'"); $sql = "SELECT * FROM `dir_people` WHERE people_status LIKE 'active' $value1 $value2 $value3 $value4 LIMIT $limit"; $query = mysql_query($sql) or die(mysql_error()); //Pre-results niceness... echo "

Results Returned: "; echo mysql_num_rows($query)." of ".mysql_num_rows($allQ)."
"; // Set up the search terms statement $terms = ""; // parse for that comma trailing problem. $comma = ""; if(strcmp($val2,'')!=0 || strcmp($val3,'')!=0 || strcmp($val4,'')!=0){$comma = ', ';}else{$comma = '';} if(strcmp($val1,'')!=0){ $terms .= $val1 . $comma;} // if isset($var) comma = ', ' if(strcmp($val3,'')!=0 || strcmp($val4,'')!=0){$comma = ', ';}else{$comma = '';} if(strcmp($val2,'')!=0){ $terms .= $val2 . $comma;} if(strcmp($val4,'')!=0){$comma = ', ';}else{$comma = '';} if(strcmp($val3,'')!=0){ $terms .= $val3 . $comma;} if(strcmp($val4,'')!=0){ $terms .= $val4 . $comma;} echo "Based on search terms: $terms

"; echo ""; $color = '#FFFFFF'; // set alternating bgcolor on the "; echo ""; echo ""; echo ""; } // Cleanup echo "
's // echo the results while ($row = mysql_fetch_array($query)){ if ($color == '#CCCCCC'){$color='#FFFFFF';}else{$color='#CCCCCC';} echo "
"; echo "".$row[people_lastname] .", ". $row[people_firstname].""; echo ""; echo $row[people_title]; echo "
"; echo "
"; // Shut down the connection so Tim Talpas doesn't yell at me. :) mysql_close($news); }