Talashira Posted October 27, 2009 Share Posted October 27, 2009 I'm creating a searchable book database. I need a drop-down from which the user can select which type of element they're looking for. I'm pretty new to PHP, so I'm not sure what I'm missing. Here is the JS: dropdown = document.getElementById("searchtype"); index = dropdown.selectedIndex; searchtype = dropdown[$index].value; $(document).ready(function() { $("#searchbox").keyup(function(){ $.get("search.php",{query: $("#searchbox").val(), query: $("#searchtype").val(), type: "count"}, function(data){ $("#buttontext").html(data + " Results Found"); }); }); $("#searchbox").keyup(function(event){ if(event.keyCode == "13") { getResults(); } }); $("#submitbutton").click(function(){ getResults(); }); function getResults() { $.get("search.php",{query: $("#searchbox").val(), query: $("#searchtype").val(), type: "results"}, function(data){ $("#resultsCont").html(data); $("#resultsCont").show("blind"); }); } }); Here is the PHP for the search form (it's incomplete for all the options in the HTML select box, but this was enough to test with, I thought): <?php $dbhost = "localhost"; $dbuser = "db_user"; $dbpass = "********"; $dbname = "db_books"; $conn = mysql_connect($dbhost, $dbuser, $dbpass) or die ('Error connecting to mysql'); mysql_select_db($dbname); if(isset($_GET['query'])) { $query = $_GET['query']; } else { $query = ""; } if(isset($_GET['type'])) { $type = $_GET['type']; } else { $query = "count"; } if($type == "count") { $sql = mysql_query("SELECT count(title) FROM books WHERE MATCH(title) AGAINST('$query' IN BOOLEAN MODE)"); $total = mysql_fetch_array($sql); $num = $total[0]; echo $num; } if($type == "results" && $searchtype == "titlesersum") { $sql = mysql_query("SELECT author_last, author_first, series, number, title, summary, genre, filename FROM books WHERE MATCH(series, title, summary) AGAINST('$query' IN BOOLEAN MODE)"); while($array = mysql_fetch_array($sql)) { $book_author_last = $array['author_last']; $book_author_first = $array['author_first']; $book_series = $array['series']; $book_number = $array['number']; $book_title = $array['title']; $book_summary = $array['summary']; $book_genre = $array['genre']; $book_length = $array['length']; $book_filename = $array['filename']; if($book_number == null){ echo "<div class=\"result\"><div class=\"resultCover\"><a href=\"content/" . $book_filename . ".pdf\" target=\"_blank\"><img src=\"covers/" . $book_filename . ".jpg\" border=\"0\" align=\"left\"></a></div><p><strong>Title</strong><br/><a href=\"content/" . $book_filename . ".pdf\" target=\"_blank\">" . $book_title . "</a><br/><br/><strong>Author</strong><br/>" . $book_author_first . " " . $book_author_last . "<br/><br/><strong>Genre</strong><br/>" . $book_genre . "<br/><br/><strong>Summary</strong><br/>" . $book_summary . "</p></div>"; } else { echo "<div class=\"result\"><div class=\"resultCover\"><a href=\"content/" . $book_filename . ".pdf\" target=\"_blank\"><img src=\"covers/" . $book_filename . ".jpg\" border=\"0\" align=\"left\"></a></div><p><strong>Title</strong><br/><a href=\"content/" . $book_filename . ".pdf\" target=\"_blank\">" . $book_title . "</a> (Book #" . $book_number . " in the " . $book_series . " Series)<br/><br/><strong>Author</strong><br/>" . $book_author_first . " " . $book_author_last . "<br/><br/><strong>Genre</strong><br/>" . $book_genre . "<br/><br/><strong>Summary</strong><br/>" . $book_summary . "</p></div>"; } } } if($type == "results" && $searchtype == "title") { $sql = mysql_query("SELECT author_last, author_first, series, number, title, summary, genre, filename FROM books WHERE MATCH(title) AGAINST('$query' IN BOOLEAN MODE)"); while($array = mysql_fetch_array($sql)) { $book_author_last = $array['author_last']; $book_author_first = $array['author_first']; $book_series = $array['series']; $book_number = $array['number']; $book_title = $array['title']; $book_summary = $array['summary']; $book_genre = $array['genre']; $book_length = $array['length']; $book_filename = $array['filename']; if($book_number == null){ echo "<div class=\"result\"><div class=\"resultCover\"><a href=\"content/" . $book_filename . ".pdf\" target=\"_blank\"><img src=\"covers/" . $book_filename . ".jpg\" border=\"0\" align=\"left\"></a></div><p><strong>Title</strong><br/><a href=\"content/" . $book_filename . ".pdf\" target=\"_blank\">" . $book_title . "</a><br/><br/><strong>Author</strong><br/>" . $book_author_first . " " . $book_author_last . "<br/><br/><strong>Genre</strong><br/>" . $book_genre . "<br/><br/><strong>Summary</strong><br/>" . $book_summary . "</p></div>"; } else { echo "<div class=\"result\"><div class=\"resultCover\"><a href=\"content/" . $book_filename . ".pdf\" target=\"_blank\"><img src=\"covers/" . $book_filename . ".jpg\" border=\"0\" align=\"left\"></a></div><p><strong>Title</strong><br/><a href=\"content/" . $book_filename . ".pdf\" target=\"_blank\">" . $book_title . "</a> (Book #" . $book_number . " in the " . $book_series . " Series)<br/><br/><strong>Author</strong><br/>" . $book_author_first . " " . $book_author_last . "<br/><br/><strong>Genre</strong><br/>" . $book_genre . "<br/><br/><strong>Summary</strong><br/>" . $book_summary . "</p></div>"; } } } if($type == "results" && $searchtype == "series") { $sql = mysql_query("SELECT author_last, author_first, series, number, title, summary, genre, filename FROM books WHERE MATCH(series) AGAINST('$query' IN BOOLEAN MODE)"); while($array = mysql_fetch_array($sql)) { $book_author_last = $array['author_last']; $book_author_first = $array['author_first']; $book_series = $array['series']; $book_number = $array['number']; $book_title = $array['title']; $book_summary = $array['summary']; $book_genre = $array['genre']; $book_length = $array['length']; $book_filename = $array['filename']; if($book_number == null){ echo "<div class=\"result\"><div class=\"resultCover\"><a href=\"content/" . $book_filename . ".pdf\" target=\"_blank\"><img src=\"covers/" . $book_filename . ".jpg\" border=\"0\" align=\"left\"></a></div><p><strong>Title</strong><br/><a href=\"content/" . $book_filename . ".pdf\" target=\"_blank\">" . $book_title . "</a><br/><br/><strong>Author</strong><br/>" . $book_author_first . " " . $book_author_last . "<br/><br/><strong>Genre</strong><br/>" . $book_genre . "<br/><br/><strong>Summary</strong><br/>" . $book_summary . "</p></div>"; } else { echo "<div class=\"result\"><div class=\"resultCover\"><a href=\"content/" . $book_filename . ".pdf\" target=\"_blank\"><img src=\"covers/" . $book_filename . ".jpg\" border=\"0\" align=\"left\"></a></div><p><strong>Title</strong><br/><a href=\"content/" . $book_filename . ".pdf\" target=\"_blank\">" . $book_title . "</a> (Book #" . $book_number . " in the " . $book_series . " Series)<br/><br/><strong>Author</strong><br/>" . $book_author_first . " " . $book_author_last . "<br/><br/><strong>Genre</strong><br/>" . $book_genre . "<br/><br/><strong>Summary</strong><br/>" . $book_summary . "</p></div>"; } } } if($type == "results" && $searchtype == "author") { $sql = mysql_query("SELECT author_last, author_first, series, number, title, summary, genre, filename FROM books WHERE MATCH(author_last, author_first) AGAINST('$query' IN BOOLEAN MODE)"); while($array = mysql_fetch_array($sql)) { $book_author_last = $array['author_last']; $book_author_first = $array['author_first']; $book_series = $array['series']; $book_number = $array['number']; $book_title = $array['title']; $book_summary = $array['summary']; $book_genre = $array['genre']; $book_length = $array['length']; $book_filename = $array['filename']; if($book_number == null){ echo "<div class=\"result\"><div class=\"resultCover\"><a href=\"content/" . $book_filename . ".pdf\" target=\"_blank\"><img src=\"covers/" . $book_filename . ".jpg\" border=\"0\" align=\"left\"></a></div><p><strong>Title</strong><br/><a href=\"content/" . $book_filename . ".pdf\" target=\"_blank\">" . $book_title . "</a><br/><br/><strong>Author</strong><br/>" . $book_author_first . " " . $book_author_last . "<br/><br/><strong>Genre</strong><br/>" . $book_genre . "<br/><br/><strong>Summary</strong><br/>" . $book_summary . "</p></div>"; } else { echo "<div class=\"result\"><div class=\"resultCover\"><a href=\"content/" . $book_filename . ".pdf\" target=\"_blank\"><img src=\"covers/" . $book_filename . ".jpg\" border=\"0\" align=\"left\"></a></div><p><strong>Title</strong><br/><a href=\"content/" . $book_filename . ".pdf\" target=\"_blank\">" . $book_title . "</a> (Book #" . $book_number . " in the " . $book_series . " Series)<br/><br/><strong>Author</strong><br/>" . $book_author_first . " " . $book_author_last . "<br/><br/><strong>Genre</strong><br/>" . $book_genre . "<br/><br/><strong>Summary</strong><br/>" . $book_summary . "</p></div>"; } } } if($type == "results" && $searchtype == "sum") { $sql = mysql_query("SELECT author_last, author_first, series, number, title, summary, genre, filename FROM books WHERE MATCH(summary) AGAINST('$query' IN BOOLEAN MODE)"); while($array = mysql_fetch_array($sql)) { $book_author_last = $array['author_last']; $book_author_first = $array['author_first']; $book_series = $array['series']; $book_number = $array['number']; $book_title = $array['title']; $book_summary = $array['summary']; $book_genre = $array['genre']; $book_length = $array['length']; $book_filename = $array['filename']; if($book_number == null){ echo "<div class=\"result\"><div class=\"resultCover\"><a href=\"content/" . $book_filename . ".pdf\" target=\"_blank\"><img src=\"covers/" . $book_filename . ".jpg\" border=\"0\" align=\"left\"></a></div><p><strong>Title</strong><br/><a href=\"content/" . $book_filename . ".pdf\" target=\"_blank\">" . $book_title . "</a><br/><br/><strong>Author</strong><br/>" . $book_author_first . " " . $book_author_last . "<br/><br/><strong>Genre</strong><br/>" . $book_genre . "<br/><br/><strong>Summary</strong><br/>" . $book_summary . "</p></div>"; } else { echo "<div class=\"result\"><div class=\"resultCover\"><a href=\"content/" . $book_filename . ".pdf\" target=\"_blank\"><img src=\"covers/" . $book_filename . ".jpg\" border=\"0\" align=\"left\"></a></div><p><strong>Title</strong><br/><a href=\"content/" . $book_filename . ".pdf\" target=\"_blank\">" . $book_title . "</a> (Book #" . $book_number . " in the " . $book_series . " Series)<br/><br/><strong>Author</strong><br/>" . $book_author_first . " " . $book_author_last . "<br/><br/><strong>Genre</strong><br/>" . $book_genre . "<br/><br/><strong>Summary</strong><br/>" . $book_summary . "</p></div>"; } } } if($type == "results" && $searchtype == "genre") { $sql = mysql_query("SELECT author_last, author_first, series, number, title, summary, genre, filename FROM books WHERE MATCH(genre) AGAINST('$query' IN BOOLEAN MODE)"); while($array = mysql_fetch_array($sql)) { $book_author_last = $array['author_last']; $book_author_first = $array['author_first']; $book_series = $array['series']; $book_number = $array['number']; $book_title = $array['title']; $book_summary = $array['summary']; $book_genre = $array['genre']; $book_length = $array['length']; $book_filename = $array['filename']; if($book_number == null){ echo "<div class=\"result\"><div class=\"resultCover\"><a href=\"content/" . $book_filename . ".pdf\" target=\"_blank\"><img src=\"covers/" . $book_filename . ".jpg\" border=\"0\" align=\"left\"></a></div><p><strong>Title</strong><br/><a href=\"content/" . $book_filename . ".pdf\" target=\"_blank\">" . $book_title . "</a><br/><br/><strong>Author</strong><br/>" . $book_author_first . " " . $book_author_last . "<br/><br/><strong>Genre</strong><br/>" . $book_genre . "<br/><br/><strong>Summary</strong><br/>" . $book_summary . "</p></div>"; } else { echo "<div class=\"result\"><div class=\"resultCover\"><a href=\"content/" . $book_filename . ".pdf\" target=\"_blank\"><img src=\"covers/" . $book_filename . ".jpg\" border=\"0\" align=\"left\"></a></div><p><strong>Title</strong><br/><a href=\"content/" . $book_filename . ".pdf\" target=\"_blank\">" . $book_title . "</a> (Book #" . $book_number . " in the " . $book_series . " Series)<br/><br/><strong>Author</strong><br/>" . $book_author_first . " " . $book_author_last . "<br/><br/><strong>Genre</strong><br/>" . $book_genre . "<br/><br/><strong>Summary</strong><br/>" . $book_summary . "</p></div>"; } } } mysql_close($conn); ?> And here is the HTML of the form, in case it helps <input type="text" id="searchbox" name="searchbox" /> <select multiple size="5" id="searchtype" name="searchtype"> <option value="title">Title</option> <option value="series">Series</option> <option value="author">Author</option> <option value="sum">Summary</option> <option value="genre">Genre</option> </select> Any help I can get would be most appreciated. And if you have any suggestions for consolidating some of the code in the .php file, that'd be terrific; I feel like a lot of the exact same information is repeated just so that the user can define different variables for the search. Link to comment https://forums.phpfreaks.com/topic/179222-adding-drop-down-to-mysql-search/ Share on other sites More sharing options...
chronister Posted October 27, 2009 Share Posted October 27, 2009 My suggestion on the PHP code is to not repeat those sections. It appears that your duplicating that one block of code numerous times, where all you really need to do is something like this.... <?php if($type == "results" && $searchtype == "titlesersum"){ $sql = "SELECT author_last, author_first, series, number, title, summary, genre, filename FROM books WHERE MATCH(series, title, summary) AGAINST('$query' IN BOOLEAN MODE)"; } if($type == "results" && $searchtype == "title"){ $sql = "SELECT author_last, author_first, series, number, title, summary, genre, filename FROM books WHERE MATCH(title) AGAINST('$query' IN BOOLEAN MODE)"; } $result = mysql_query($sql); while($array = mysql_fetch_array($result)) { $book_author_last = $array['author_last']; $book_author_first = $array['author_first']; $book_series = $array['series']; $book_number = $array['number']; $book_title = $array['title']; $book_summary = $array['summary']; $book_genre = $array['genre']; $book_length = $array['length']; $book_filename = $array['filename']; if($book_number == null){ echo "<div class=\"result\"><div class=\"resultCover\"><a href=\"content/" . $book_filename . ".pdf\" target=\"_blank\"><img src=\"covers/" . $book_filename . ".jpg\" border=\"0\" align=\"left\"></a></div><p><strong>Title</strong><br/><a href=\"content/" . $book_filename . ".pdf\" target=\"_blank\">" . $book_title . "</a><br/><br/><strong>Author</strong><br/>" . $book_author_first . " " . $book_author_last . "<br/><br/><strong>Genre</strong><br/>" . $book_genre . "<br/><br/><strong>Summary</strong><br/>" . $book_summary . "</p></div>"; } else { echo "<div class=\"result\"><div class=\"resultCover\"><a href=\"content/" . $book_filename . ".pdf\" target=\"_blank\"><img src=\"covers/" . $book_filename . ".jpg\" border=\"0\" align=\"left\"></a></div><p><strong>Title</strong><br/><a href=\"content/" . $book_filename . ".pdf\" target=\"_blank\">" . $book_title . "</a> (Book #" . $book_number . " in the " . $book_series . " Series)<br/><br/><strong>Author</strong><br/>" . $book_author_first . " " . $book_author_last . "<br/><br/><strong>Genre</strong><br/>" . $book_genre . "<br/><br/><strong>Summary</strong><br/>" . $book_summary . "</p></div>"; } } } ?> See how I have the Query in the IF() statements and the code that deals with the results below. The code that displays the information looked the same, you only have to write that once, and just use if statements or even a switch statement to determine which query needs to be ran. That will save a lot of code. As far as the rest of it, give more detail as to what you need help with. I am not clear as to exactly what you are looking for. Link to comment https://forums.phpfreaks.com/topic/179222-adding-drop-down-to-mysql-search/#findComment-945633 Share on other sites More sharing options...
Talashira Posted October 27, 2009 Author Share Posted October 27, 2009 Thanks, chronister! That's just what I was looking for as far as consolidation is concerned. As for my actual request, what I want in the HTML is a list of checkbox options, and I want the PHP to pull the value of whatever options they've selected in to the PHP. So the HTML will look like this: <input type="text" id="searchbox" name="searchbox" /> <input type="checkbox" id="searchtype" name="searchtype" value="title" />Title<br/> <input type="checkbox" id="searchtype" value="series" />Series<br/> <input type="checkbox" id="searchtype" value="author_first,author_last" />Author<br/> <input type="checkbox" id="searchtype" value="summary" />Summary<br/> <input type="checkbox" id="searchtype" value="genre" />Genre<br/> ...and the PHP will look something like this: <?php if($type == "results" && $searchtype == "series,title,summary"){ $sql = "SELECT author_last, author_first, series, number, title, summary, genre, filename FROM books WHERE MATCH(series, title, summary) AGAINST('$query' IN BOOLEAN MODE)"; } $result = mysql_query($sql); while($array = mysql_fetch_array($result)) { $book_author_last = $array['author_last']; $book_author_first = $array['author_first']; $book_series = $array['series']; $book_number = $array['number']; $book_title = $array['title']; $book_summary = $array['summary']; $book_genre = $array['genre']; $book_length = $array['length']; $book_filename = $array['filename']; if($book_number == null){ echo "<div class=\"result\"><div class=\"resultCover\"><a href=\"content/" . $book_filename . ".pdf\" target=\"_blank\"><img src=\"covers/" . $book_filename . ".jpg\" border=\"0\" align=\"left\"></a></div><p><strong>Title</strong><br/><a href=\"content/" . $book_filename . ".pdf\" target=\"_blank\">" . $book_title . "</a><br/><br/><strong>Author</strong><br/>" . $book_author_first . " " . $book_author_last . "<br/><br/><strong>Genre</strong><br/>" . $book_genre . "<br/><br/><strong>Summary</strong><br/>" . $book_summary . "</p></div>"; } else { echo "<div class=\"result\"><div class=\"resultCover\"><a href=\"content/" . $book_filename . ".pdf\" target=\"_blank\"><img src=\"covers/" . $book_filename . ".jpg\" border=\"0\" align=\"left\"></a></div><p><strong>Title</strong><br/><a href=\"content/" . $book_filename . ".pdf\" target=\"_blank\">" . $book_title . "</a> (Book #" . $book_number . " in the " . $book_series . " Series)<br/><br/><strong>Author</strong><br/>" . $book_author_first . " " . $book_author_last . "<br/><br/><strong>Genre</strong><br/>" . $book_genre . "<br/><br/><strong>Summary</strong><br/>" . $book_summary . "</p></div>"; } } } ?> I need the following: [*]A way of pulling in all selections (the value of the checkboxes) made by the user in the HTML form -- basically the creation of the $searchtype parameter. [*]A way in the PHP to match those values to the WHERE MATCH list in the original "if($type/$searchtype" statement. So, if the user selected "title" and "series", the PHP would automatically know to look for just "title" and "series". I just need the $searchtype parameter to match whatever the user has selected, then have that same parameter be parsed out in WHERE MATCH as a comma-delimited list. Hope that makes sense! Link to comment https://forums.phpfreaks.com/topic/179222-adding-drop-down-to-mysql-search/#findComment-945647 Share on other sites More sharing options...
chronister Posted October 27, 2009 Share Posted October 27, 2009 Ok, set the search form up like this... <input type="text" id="searchbox" name="searchbox" /> <input type="checkbox" id="searchtype" name="searchType[]" value="title" />Title<br/> <input type="checkbox" id="searchtype" name="searchType[]" value="series" />Series<br/> <input type="checkbox" id="searchtype" name="searchType[]" value="author_first,author_last" />Author<br/> <input type="checkbox" id="searchtype" name="searchType[]" value="summary" />Summary<br/> <input type="checkbox" id="searchtype" name="searchType[]" value="genre" />Genre<br/> This will make the searchType field become a variable on the backend. You can then use $_POST['searchType'] as an array item and loop through it. <?php foreach($_POST['searchType'] as $searchType){ echo $searchType.', '; } ?> [code] I think that will give you a nudge in the right direction. See what you can do with that and post back if you have questions after. Nate Link to comment https://forums.phpfreaks.com/topic/179222-adding-drop-down-to-mysql-search/#findComment-945710 Share on other sites More sharing options...
Talashira Posted October 27, 2009 Author Share Posted October 27, 2009 It's definitely closer, but I got a combination of errors that is saying that that code is invalid: Warning: Invalid argument supplied for foreach() on line 11 Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource on line 30 Here's the code as it looks now: <?php $dbhost = "localhost"; $dbuser = "db_user"; $dbpass = "********"; $dbname = "db_name"; $conn = mysql_connect($dbhost, $dbuser, $dbpass) or die ('Error connecting to mysql'); mysql_select_db($dbname); foreach($_POST["searchType"] as $searchType){ echo $searchType.", "; } if(isset($_GET['query'])) { $query = $_GET['query']; } else { $query = ""; } if(isset($_GET['type'])) { $type = $_GET['type']; } else { $query = "count"; } if($type == "count") { $sql = mysql_query("SELECT count(title) FROM books WHERE MATCH(author_last, author_first, series, number, title, summary, number, genre, filename) AGAINST('$query' IN BOOLEAN MODE)"); $total = mysql_fetch_array($sql); $num = $total[0]; echo $num; } if($type == "results"){ $sql = "SELECT author_last, author_first, series, number, title, summary, genre, filename FROM books WHERE MATCH('$searchType') AGAINST('$query' IN BOOLEAN MODE)"; } $result = mysql_query($sql); while($array = mysql_fetch_array($result)) { $book_author_last = $array['author_last']; $book_author_first = $array['author_first']; $book_series = $array['series']; $book_number = $array['number']; $book_title = $array['title']; $book_summary = $array['summary']; $book_genre = $array['genre']; $book_length = $array['length']; $book_filename = $array['filename']; if($book_number == null){ echo "<div class=\"result\"><div class=\"resultCover\"><a href=\"content/" . $book_filename . ".pdf\" target=\"_blank\"><img src=\"covers/" . $book_filename . ".jpg\" border=\"0\" align=\"left\"></a></div><p><strong>Title</strong><br/><a href=\"content/" . $book_filename . ".pdf\" target=\"_blank\">" . $book_title . "</a><br/><br/><strong>Author</strong><br/>" . $book_author_first . " " . $book_author_last . "<br/><br/><strong>Genre</strong><br/>" . $book_genre . "<br/><br/><strong>Summary</strong><br/>" . $book_summary . "</p></div>"; } else { echo "<div class=\"result\"><div class=\"resultCover\"><a href=\"content/" . $book_filename . ".pdf\" target=\"_blank\"><img src=\"covers/" . $book_filename . ".jpg\" border=\"0\" align=\"left\"></a></div><p><strong>Title</strong><br/><a href=\"content/" . $book_filename . ".pdf\" target=\"_blank\">" . $book_title . "</a> (Book #" . $book_number . " in the " . $book_series . " Series)<br/><br/><strong>Author</strong><br/>" . $book_author_first . " " . $book_author_last . "<br/><br/><strong>Genre</strong><br/>" . $book_genre . "<br/><br/><strong>Summary</strong><br/>" . $book_summary . "</p></div>"; } } mysql_close($conn); ?> ...and the HTML (I changed it a bit to utilize this script: http://dropdown-check-list.googlecode.com/svn/trunk/demo.html): <select multiple="multiple" id="searchType" name="searchType[]"> <option>Search All</option> <option value="title" selected="selected">Title</option> <option value="author">Author</option> <option value="series" selected="selected">Series</option> <option value="summary" selected="selected">Summary</option> <option value="genre">Genre</option> </select> I've also tried this: <select multiple="multiple" id="searchType"> <option>Search All</option> <option value="title" selected="selected" name="searchType[]">Title</option> <option value="author" name="searchType[]">Author</option> <option value="series" selected="selected" name="searchType[]">Series</option> <option value="summary" selected="selected" name="searchType[]">Summary</option> <option value="genre" name="searchType[]">Genre</option> </select> Thank you so much for your help. I'm learning quite a bit from you. Link to comment https://forums.phpfreaks.com/topic/179222-adding-drop-down-to-mysql-search/#findComment-945725 Share on other sites More sharing options...
chronister Posted October 27, 2009 Share Posted October 27, 2009 hmmmm.... the warning on the foreach means the variable you passed to it is not an array item. the warning on the mysql_fetch_array() means that a proper mysql resource was not given to it. I am at work right now, but will look into this later when I get home and actually have my tools and resources. Notepad does not do much. Nate Link to comment https://forums.phpfreaks.com/topic/179222-adding-drop-down-to-mysql-search/#findComment-945758 Share on other sites More sharing options...
Talashira Posted October 28, 2009 Author Share Posted October 28, 2009 Wow. Thank you so much! Let me know if having the link to the site would help, or a .zip of the files (I can upload it for you to grab). Link to comment https://forums.phpfreaks.com/topic/179222-adding-drop-down-to-mysql-search/#findComment-945955 Share on other sites More sharing options...
chronister Posted October 30, 2009 Share Posted October 30, 2009 Have you gotten anywhere with this thread? If not here is what I would suggest. Change ... name="searchType[]"> to name="searchType"> Then echo $_POST['searchType'], and see what you get. I am thinking that you will get something like this..... item1, item2, item3 ...etc. If this is the case, then it will be a little more work to break apart that string and determine what you want to search by. But do the above and post back with what you get. If it is what I am thinking, then the tips I gave before are now NULL. Nate Link to comment https://forums.phpfreaks.com/topic/179222-adding-drop-down-to-mysql-search/#findComment-947980 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.