ash85 Posted July 17, 2010 Share Posted July 17, 2010 Hiya, I am new to php , mysql so kindly be nice My problem -> Created a dynamic website. When i put this bit of code , it allows me to search both location and genre BUT if i select only location and nothing from genre then it does not work . same for if i select genre only , it not work. So i have to select both from location and genre for it to work. $result = mysql_query("SELECT * FROM bands WHERE location in ('$location') AND genre in ('$genre')") or die(mysql_error()); Now , if i change AND to OR , i am able to get result with only selecting location or genre but nothing when select from both. I tried mixing and / or , played with brackets etc but no good. Been stuck on this almost 2 days. Please can anyone help me here ? I just need the search to be like , the user may select one / multiple from location + one/multiple from genre OR one/multiple from location only or one/multiple from genre only .....any permutaion combination should work. if that makes sense cheers. Quote Link to comment https://forums.phpfreaks.com/topic/208042-strange-problem-please-help/ Share on other sites More sharing options...
PFMaBiSmAd Posted July 17, 2010 Share Posted July 17, 2010 OR should have worked. Could you form the query string in a variable (i.e. $query) and echo and post it along with example data showing what the location and genre columns contain that should match the query you are trying. Quote Link to comment https://forums.phpfreaks.com/topic/208042-strange-problem-please-help/#findComment-1087509 Share on other sites More sharing options...
ash85 Posted July 17, 2010 Author Share Posted July 17, 2010 The WARNING i get is Warning: implode() [function.implode]: Invalid arguments passed in C:\xampp\htdocs\M1\advanced.php on line 73 I think its when only one field is selected and not both then the implode behaves silly. :-\ Quote Link to comment https://forums.phpfreaks.com/topic/208042-strange-problem-please-help/#findComment-1087510 Share on other sites More sharing options...
PFMaBiSmAd Posted July 17, 2010 Share Posted July 17, 2010 THAT error is because you are not passing an array to a function that expects and array. That has nothing to do with your mysql query question. Why cannot people provide actual information that they know about a problem when they ask a for help No one can really help you with what is wrong with your code without seeing the actual code responsible for the symptom and the symptom. Quote Link to comment https://forums.phpfreaks.com/topic/208042-strange-problem-please-help/#findComment-1087512 Share on other sites More sharing options...
ash85 Posted July 17, 2010 Author Share Posted July 17, 2010 <?php $location = implode("', '",$_POST['location']); $genre = implode("', '",$_POST['genre']); // Make a MySQL Connection mysql_connect("localhost", "username", "password") or die(mysql_error()); mysql_select_db("db") or die(mysql_error()); $result = mysql_query("SELECT * FROM bands WHERE (location in ('$location') AND genre in ('$genre')) OR (location in ('$location') OR genre in ('$genre')) ") or die(mysql_error()); echo "<table border='5'>"; echo "<tr> <th>Day</th> <th>Genre</th> <th>Location</th> <th>Name</th> </tr>"; // keeps getting the next row until there are no more to get while($row = mysql_fetch_array( $result )) { // Print out the contents of each row into a table echo "<tr><td>"; echo $row['Day']; echo "</td><td>"; echo $row['Genre']; echo "</td><td>"; echo $row['Location']; echo "</td><td>"; echo $row['Name']; echo "</td></tr>"; } echo "</table>"; ?> Quote Link to comment https://forums.phpfreaks.com/topic/208042-strange-problem-please-help/#findComment-1087513 Share on other sites More sharing options...
ash85 Posted July 17, 2010 Author Share Posted July 17, 2010 Thats the form code. <form id="form1" method="post" action="advanced.php"> <p> <label>Location <select name="location[]" size="3" multiple="multiple" id="location"> <option value="Old Trafford">Old Trafford</option> <option value="Manchester Arena">Manchester Arena</option> </select> </label> <label> Genre <select name="genre[]" size="3" multiple="multiple" id="genre"> <option value="Pop">Pop</option> <option value="Rock">Rock</option> </select> </label> </p> <p> <input type="submit" name="go" id="go" value="Submit" /> </p> <p> </p> </form> Quote Link to comment https://forums.phpfreaks.com/topic/208042-strange-problem-please-help/#findComment-1087515 Share on other sites More sharing options...
ash85 Posted July 17, 2010 Author Share Posted July 17, 2010 thats all info mate . Quote Link to comment https://forums.phpfreaks.com/topic/208042-strange-problem-please-help/#findComment-1087516 Share on other sites More sharing options...
ash85 Posted July 17, 2010 Author Share Posted July 17, 2010 Anyone ? Quote Link to comment https://forums.phpfreaks.com/topic/208042-strange-problem-please-help/#findComment-1087564 Share on other sites More sharing options...
ash85 Posted July 19, 2010 Author Share Posted July 19, 2010 I can't think what may be going wrong ...... no guru here to help ? Quote Link to comment https://forums.phpfreaks.com/topic/208042-strange-problem-please-help/#findComment-1088170 Share on other sites More sharing options...
ash85 Posted July 19, 2010 Author Share Posted July 19, 2010 solver the implode problem by having and IF statement . But still cant seem to get mixed results. Quote Link to comment https://forums.phpfreaks.com/topic/208042-strange-problem-please-help/#findComment-1088213 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.