Note that there are some explanatory texts on larger screens.

plurals
  1. POMySQL/PHP Search Script - Setting Search Parameters?
    primarykey
    data
    text
    <p>I have a MySQL table with contains a lot of trivia questions. Each entry (row) has a few columns (ID, Question #, Category, Difficulty, Question, Answer). I have a search engine set-up that queries the database like such(the HTML forms sends the search to a php script that queries the database and retrieves the info back)</p> <p>search.php:</p> <pre><code>&lt;?php $button = $_GET ['submit']; $search = $_GET ['search']; if(strlen($search)&lt;=1) echo "Search term too short"; else{ echo "You searched for &lt;b&gt;&lt;em&gt;$search&lt;/em&gt;&lt;/b&gt; and "; mysql_connect("mydb","notmypony","ponyrocksagain#"); mysql_select_db("quinterestdb");} $search_exploded = explode (" ", $search); foreach($search_exploded as $search_each) { $x++; if($x==1) $construct .="Answer LIKE '%$search_each%'"; else $construct .="AND Answer LIKE '%$search_each%'"; } $constructs ="SELECT * FROM tossups WHERE $construct"; $run = mysql_query($constructs); $foundnum = mysql_num_rows($run); if ($foundnum==0) echo "Sorry, there are no matching result for &lt;b&gt;$search&lt;/b&gt;.&lt;/br&gt;&lt;/br&gt;1. Try more general words. for example: If you want to search 'how to create a website' then use general keyword like 'create' 'website'&lt;/br&gt;2. Try different words with similar meaning&lt;/br&gt;3. Please check your spelling"; else { echo " &lt;span class='badge badge-info'&gt; $foundnum &lt;/span&gt; results were found:&lt;hr size='5'&gt;"; $per_page = 25; $start = $_GET['start']; $max_pages = ceil($foundnum / $per_page); if(!$start) $start=0; $getquery = mysql_query("SELECT * FROM tossups WHERE $construct LIMIT $start, $per_page"); while($runrows = mysql_fetch_assoc($getquery)) { $answer = $runrows ['Answer']; $category = $runrows ['Category']; $num = $runrows ['Question #']; $difficulty = $runrows ['Difficulty']; $question = $runrows ['Question']; $round = $runrows ['Round']; $tournament = $runrows ['Tournament']; $year = $runrows ['Year']; echo "&lt;div class='alert alert-info' style='border-radius: 20px'&gt;&lt;div style='padding: 10px'&gt; &lt;span class='label label-info' font-size='30px'&gt;&lt;em&gt;Tournament | Year | Round | Question # | Category&lt;/em&gt;&lt;/span&gt;&lt;/div&gt; &lt;b&gt;$tournament |&lt;/b&gt; &lt;b&gt;$year |&lt;/b&gt; &lt;b&gt;$round |&lt;/b&gt; &lt;b&gt;$num |&lt;/b&gt; &lt;b&gt;$category&lt;/b&gt; &lt;p&gt;&lt;em&gt;Question:&lt;/em&gt; $question&lt;/p&gt; &lt;div class='alert alert-info'&gt;&lt;em&gt;&lt;strong&gt;ANSWER:&lt;/strong&gt;&lt;/em&gt; $answer&lt;/div&gt;&lt;/div&gt;&lt;hr&gt; "; } </code></pre> <p>My goal here is to be able to add a drop-down menu to the search form that allows the user to select a category that will restrict the results to that selected category. I'm at loss as to how to accomplish this. Any help would be greatly appreciated. I'm eager to learn. Anyways, if you're interested in viewing the project it is available <a href="http://www.quinterest.org" rel="nofollow">here</a></p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload