trickadee Posted May 26, 2010 Share Posted May 26, 2010 Hi there, I'd really love some help for an assignment I'm doing. I want my users to search my database of downloadable ESL resources. I've managed to be able to run a key word search that returns results that have the key word in the title or tags. At the same time, I want to be able to filter those results by level- beginner, intermediate and advanced. In my database, I have a column for 'level' that has any combination of these three words in it for each entry. My search form has checkboxes for these three words. How do I add in the functionality to filter my results by level? Your help will be much appreciated!! <!-- Search form --> <p> Search these resources:</p> <form method="post" action=""> <input type="text" name="search" size=25 maxlength=25> Beginner <input value="beginner" name="level[]" type="checkbox"> Intermediate <input value="intermediate" name="level[]" type="checkbox"> Advanced <input value="advanced" name="level[]" type="checkbox"> <input type="Submit" name="Submit" value="Submit"> </form> <?php //select database $database="a4186211_wp"; mysql_connect ("mysql12.000webhost.com", "a4186211_tsr", "password"); @mysql_select_db($database) or die( "Unable to select database"); $search=$_POST["search"]; //get the mysql and store them in $result $result = mysql_query("SELECT * FROM Resources WHERE name LIKE '%$search%' OR tags LIKE '%$search%'"); //grab all the content while ($get_info = mysql_fetch_array($result)){ $series[] = array('name' => $get_info['name'], 'url' => $get_info['url'], 'tags' => $get_info['tags'], 'level' => $get_info['level']); } ?> <!-- Show Content --> <p>Here are all the resources...</p> <?php foreach ($series as $show): ?> <blockquote> <h2><?php echo htmlspecialchars($show['name'], ENT_QUOTES, 'UTF-8'); ?></h2> <p><em><a href="http://www.tracyr.comlu.com/SFVT/upload/<?php echo htmlspecialchars($show['url'], ENT_QUOTES, 'UTF-8'); ?>">click to download file </a></em><br/> <em><?php echo htmlspecialchars($show['tags'], ENT_QUOTES, 'UTF-8'); ?></em> </p></blockquote> <?php endforeach; ?> Link to comment https://forums.phpfreaks.com/topic/202935-searching-my-db-using-checkboxes/ Share on other sites More sharing options...
gwolgamott Posted May 26, 2010 Share Posted May 26, 2010 Take that variable column, run a string compare function of some type against it inside of an if statement. Link to comment https://forums.phpfreaks.com/topic/202935-searching-my-db-using-checkboxes/#findComment-1063630 Share on other sites More sharing options...
gwolgamott Posted May 26, 2010 Share Posted May 26, 2010 Use some of these in link, or make you own function. A note on how to add them into your function though, not sure where you'd want to do that. So at risk of taking stab in the dark, just say just run the query on the name, dump rest in of columns into an array and then filter the results out of the array. Then after you get that to work the way you want work backwards to make it more efficient. http://w3schools.com/php/php_ref_string.asp Link to comment https://forums.phpfreaks.com/topic/202935-searching-my-db-using-checkboxes/#findComment-1063652 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.