crochk Posted September 19, 2008 Share Posted September 19, 2008 I have a MySQL database of files. I want the users to be able to search the database by the content using FULLTEXT searching or search by id#. The search form is a text filed (find) and a drop down menu to choose the field (field). The problem: My search php code is having a small problem. I know the id code and content code work seperatly, but when combined as below, only the first one will work (in this case 'content'). <?php //PROCESS SEARCH if(isset($_POST['search']) && isset($_POST['find'])) { //GET INFORMATION FROM FORM $search = $_POST['find']; $field = $_POST['field']; //SEARCH DATABASE if($field = 'content') { $sql = mysql_query("SELECT * FROM submit WHERE MATCH (filetitle,filecontent) AGAINST('$search')") or die('Error: ' . mysql_error()); } elseif($field = 'id') { $sql = mysql_query("SELECT * FROM submit WHERE submitID = $search"); } echo "<h2>RESULTS</h2>"; //IF NO MATCHES $matches = mysql_num_rows($sql); if($matches == '0') { exit("No matches found"); } else { echo "<p><strong>Number of Results: " . $matches; echo "</strong></p><p> </p>"; //DISPLAY RESULTS echo "<div id='searchScroll'>"; while($row = mysql_fetch_array($sql)) { echo "<div id='entry'> <p>#" . $row['submitID'] . " - <a href= ../pages/download.php?id=" . urlencode($row['submitID']) . ">" . $row['filetitle'] . "</a><br /> <span id=entryid>Grade " . $row['filegrade'] . " - " . $row['filesubject'] . "<br /> Year Created: " . $row['fileyear'] . "</span></p> </div>"; } echo "</div>"; } } ?> Thank you. Link to comment https://forums.phpfreaks.com/topic/124886-solved-searching-using-php/ Share on other sites More sharing options...
Maq Posted September 19, 2008 Share Posted September 19, 2008 First problem... You're assigning $field to content instead of comparing. Change: if($field = 'content') To: if($field == 'content') Link to comment https://forums.phpfreaks.com/topic/124886-solved-searching-using-php/#findComment-645350 Share on other sites More sharing options...
Maq Posted September 19, 2008 Share Posted September 19, 2008 Same here: elseif($field = 'id') Needs to be: elseif($field == 'id') Link to comment https://forums.phpfreaks.com/topic/124886-solved-searching-using-php/#findComment-645351 Share on other sites More sharing options...
crochk Posted September 19, 2008 Author Share Posted September 19, 2008 Dumb mistake Thank you Link to comment https://forums.phpfreaks.com/topic/124886-solved-searching-using-php/#findComment-645871 Share on other sites More sharing options...
Maq Posted September 19, 2008 Share Posted September 19, 2008 Hehe, happens to all of us! Link to comment https://forums.phpfreaks.com/topic/124886-solved-searching-using-php/#findComment-645876 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.