Advertisement

07.30.2008 at 06:35AM PDT, ID: 23607232
[x]
Attachment Details
[x]
The Solution Rating System

With so many solutions, how can you tell which solutions are most likely to help you and which ones are not? To provide you with a tool to use, we rate our solutions based on various elements that most accurately determine if a solution is a quality solution. To explain what factors affect the solution rating, here are the elements we take into consideration when formulating our solution rating.

  • The Grade of the Solution
  • The Zone Rank of the Expert Providing the Solution
  • The Number of Author and Expert Comments
  • The Number of Experts Contributing
  • The Feedback of the Community

Your Input Matters
Because of the way the system is set up, the most important variable in this equation is you. As a member of Experts Exchange, you are able to cast your vote on the quality of the solutions in regard to how complete, accurate, helpful and easy to understand each solution is. When you provide your feedback, each rating is adjusted accordingly. So, if you see a solution that has a poor rating that you think is a good solution, let us know by rating it. As you do, the rating will be adjusted and will become more accurate for other members of our site.

If you have any suggestions that you would like to make for our rating system, please ask a question in the Suggestions Zone of Community Support.

Thank you!

9.1

SQL query with Boolean

Asked by jbpeake in MySQL Server, PHP and Databases, SQL Query Syntax

Tags: , ,

Hello experts,

I am learning to create SQL statements and have hit a problem I can't figure out.  The website is www.agteacher.com/search.php and the username is student and the password is student.  In the code I have created you can see that I have figured out how to do a simple query where I count my results for pagination and also search multiple columns looking for matches to the user supplied search string.  Here is where I am getting stuck.

When someone searches for "Breeds of Cattle"  right now they only get back the exact matches for "Breeds of Cattle", I would like for them to also get back "Breeds of Beef Cattle" and "Breeds of Dairy Cattle" etc.  I have been reading the MySQL Development manual on Boolean searches, but I can't seem to make it work for multiple words.  I tried explode(" ", $searchstring) to create an array and I can get the array to print,  but I don't understand how to do a Boolean search across multiple fields using an array.

Getting to where I am now has been tough and I'm not sure what to do next. Start Free Trial
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
39:
40:
41:
42:
43:
44:
45:
46:
47:
48:
49:
50:
51:
52:
53:
54:
55:
56:
57:
58:
59:
60:
61:
62:
63:
64:
65:
66:
67:
68:
69:
70:
71:
72:
73:
74:
75:
76:
77:
78:
79:
80:
81:
82:
83:
84:
85:
86:
87:
88:
89:
90:
91:
92:
93:
94:
95:
96:
97:
98:
99:
100:
101:
102:
103:
104:
105:
106:
107:
108:
109:
110:
echo '<span class=headers>Search Lessons</span>'; 
 
if($session->logged_in){
		
if (isset($_GET['pageno'])) {
   $pageno = $_GET['pageno'];
} else {
   $pageno = 1;
} // if
 
  $searchwords = (isset($_GET['words']) ? htmlspecialchars(stripslashes($_REQUEST['words'])) : ''); 
   
  echo '<form method="get" action="'.$_SERVER['PHP_SELF'].'">'; 
  echo '<input type="text" name="words" size="50" value="'.$searchwords.'" /> '; 
  echo '<input type="submit" value="Search" />'; 
  echo '</form>'; 
 
$searchstring = mysql_real_escape_string($_GET['words']); 
$searcharray = explode(" ", $searchstring) ;
print_r($searcharray);
 
if ($searchstring !== "") {
 
$query = "SELECT count(*) FROM all_lessons WHERE lesson_name like '%$searchstring%' OR keyword like '%$searchstring%' OR author like '%$searchstring%' OR state like '%$searchstring%'";    
$result = mysql_query($query) or die (mysql_error()); 
$query_data = mysql_fetch_row($result);
$numrows = $query_data[0];
}
 
$rows_per_page = 10;
$lastpage      = ceil($numrows/$rows_per_page);
$pageno = (int)$pageno;
if ($pageno > $lastpage) {
   $pageno = $lastpage;
} // if
if ($pageno < 1) {
   $pageno = 1;
} // if
$limit = 'LIMIT ' .($pageno - 1) * $rows_per_page .',' .$rows_per_page;
 
$query = "SELECT * FROM all_lessons WHERE lesson_name like '%$searchstring%' OR keyword like '%$searchstring%' OR author like '%$searchstring%' OR state like '%$searchstring%' ORDER BY id DESC $limit ";
$result = mysql_query($query) or die (mysql_error()); 
if ($searchstring == "") {
echo "<span class=headers>Enter a Search</span>";
}
 
else {
  	echo "<span class='bodytext'>You searched for " . $searchstring . " and found " . $numrows . " item(s)</span><br>" ; 
	   
   while($row = mysql_fetch_object($result))
    { 
 
echo '<br><span class=headers> '.stripslashes(htmlspecialchars($row->lesson_name)) . '</span>&nbsp;<br><span class=bodytext> by ' . ($row->author) . ' of ' . ($row->state) . ' on ' . ($row->today_date) . '</span>';
 
if ($session->isAdmin()) {
	echo "&nbsp;&nbsp;<span class='bodytext'><a href='search.php?id=" . $row->id . "&remove=yes&words=" . $searchstring . "'>delete</a>";
}
	
    $file_size1=round($row->size1/1024);  
    $file_size2=round($row->size2/1024);  
    $file_size3=round($row->size3/1024);  
    $file_size4=round($row->size4/1024);  
    $file_size5=round($row->size5/1024);  
      
if ($row->size1 > "100") {
      echo '<br><span class=bodytext><a href=upload/'.$row->name1. ' target=blank>'.stripslashes(htmlspecialchars($row->item_type1)).'</a> - <span class=bodytext>' . $file_size1 . ' KB</span>'; 
}
if ($row->size2 > "100") {
      echo '<br><span class=bodytext><a href=upload/'.$row->name2. ' target=blank>'.stripslashes(htmlspecialchars($row->item_type2)).'</a> - <span class=bodytext>' . $file_size2 . ' KB</span>'; 
}
if ($row->size3 > "100") {
      echo '<br><span class=bodytext><a href=upload/'.$row->name3. ' target=blank>'.stripslashes(htmlspecialchars($row->item_type3)).'</a> - <span class=bodytext>' . $file_size3 . ' KB</span>'; 
}
if ($row->size4 > "100") {
      echo '<br><span class=bodytext><a href=upload/'.$row->name4. ' target=blank>'.stripslashes(htmlspecialchars($row->item_type4)).'</a> - <span class=bodytext>' . $file_size4 . ' KB</span>'; 
}
if ($row->size5 > "100") {
      echo '<br><span class=bodytext><a href=upload/'.$row->name5. ' target=blank>'.stripslashes(htmlspecialchars($row->item_type5)).'</a> - <span class=bodytext>' . $file_size5 . ' KB</span>'; 
}
      echo '<hr size="1" />'; 
      
} 
} 
echo "<br><br><span class=headers>";
 
if ($pageno == 1) {
   echo " First &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Previous &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;";
} else {
   echo " <a href='{$_SERVER['PHP_SELF']}?pageno=1&words=$searchwords'>First</a> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ";
   $prevpage = $pageno-1;
   echo " <a href='{$_SERVER['PHP_SELF']}?pageno=$prevpage&words=$searchwords'>Previous</a> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ";
} // if
 
echo " ( Page $pageno of $lastpage ) &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;";
 
if ($pageno == $lastpage) {
   echo " Next &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Last";
} else {
   $nextpage = $pageno+1;
   echo " <a href='{$_SERVER['PHP_SELF']}?pageno=$nextpage&words=$searchwords'>Next &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</a> ";
   echo " <a href='{$_SERVER['PHP_SELF']}?pageno=$lastpage&words=$searchwords'>Last</a> ";
} // if
 
}
else{
	echo "<span class='bodytext'><br><br>You must <a href='register.php'>register</a> and <a href='main.php'>login </a href> to search for lessons.";
}
 
include('footer.php');
?>
[+][-]07.30.2008 at 07:10AM PDT, ID: 22120551

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]07.30.2008 at 07:10AM PDT, ID: 22120557

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]07.30.2008 at 07:11AM PDT, ID: 22120570

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]07.30.2008 at 11:11AM PDT, ID: 22123023

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]07.30.2008 at 11:16AM PDT, ID: 22123083

View this solution now by starting your 7-day free trial. Setting up your free trial is quick, easy, and secure. We will return you to this solution, unlocked, when you're done.

 

About this solution

Zones: MySQL Server, PHP and Databases, SQL Query Syntax
Tags: sql mysql php, Mozilla Firefox 2.0.0.16, http://www.agteacher.com/search.php username=student password=student
Sign Up Now!
Solution Provided By: virmaior
Participating Experts: 2
Solution Grade: A
 
 
[+][-]07.30.2008 at 12:04PM PDT, ID: 22123578

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
 
Loading Advertisement...
20080716-EE-VQP-32 / EE_QW_2_20070628