* This file searches the database **************************************************************************************/ //Get variables from config.php to connect to mysql server require 'configit.php'; // connect to the mysql database server. mysql_connect ($dbhost, $dbusername, $dbuserpass); //select the database mysql_select_db($dbname) or die('Cannot select database'); //search variable = data in search box or url if(isset($_GET['search'])) { $search = $_GET['search']; } //trim whitespace from variable $search = trim($search); $search = preg_replace('/\s+/', ' ', $search); //seperate multiple keywords into array space delimited $keywords = explode(" ", $search); //Clean empty arrays so they don't get every row as result $keywords = array_diff($keywords, array("")); //Set the MySQL query if ($search == NULL or $search == '%'){ } else { for ($i=0; $i"; echo "
"; echo ""; echo " "; echo "
"; //If search variable is null do nothing, else print it. if ($search == NULL) { } else { echo "You searched for "; foreach($keywords as $value) { print "$value "; } echo ""; } echo ""; //If users doesn't enter anything into search box tell them to. if ($search == NULL){ echo "Please enter a search parameter to continue.
"; } elseif ($search == '%'){ echo "Please enter a search parameter to continue.
"; //If no results are returned print it } elseif ($count <= 0){ echo "
Your query returned no results from the database.
"; //ELSE print the data in a table } else { //While there are rows, print it. while($row = mysql_fetch_array($result)) { //Row color alternates for each row $row_color = ($row_count % 2) ? $color1 : $color2; //table background color = row_color variable echo "

".$row['quote']."
"; echo "".$row['author']."
"; echo "".$row['complem']." played by "; echo "".$row['name']." "; echo "".$row['comments']." "; $row_count++; //end while } //end if } if ($search == NULL or $search == '%') { } else { //clear memory mysql_free_result($result); } ?>