pudge1 Posted August 16, 2010 Share Posted August 16, 2010 $user = SQL_User(); $pass = SQL_Pass(); $dbname = SQL_DB(); $search_term = mysql_real_escape_string($search_term); $connection = mysql_connect('localhost',$user,$pass); mysql_select_db($dbname, $connection); $sql = "SELECT * FROM Notes WHERE Keywords LIKE '%$search_term%'"; if($subject == 'NO') { } else { $sql .= " AND Subject='$subject'"; } if($grade == 'NO') { } else { $sql .= " AND Grade='$grade'"; } if($sort_by == 'NO') { } elseif($sort_by == 'RATING') { $sql .= " ORDER BY Rating DESC"; } elseif($sort_by == 'VIEWS') { $sql .== " ORDER BY Views DESC"; } else { } $query = mysql_query($sql, $connection); $query = mysql_fetch_array($query); Will query output a multi-dimensional array? If not how does it separate each result? Quote Link to comment https://forums.phpfreaks.com/topic/210896-search-system/ Share on other sites More sharing options...
pudge1 Posted August 17, 2010 Author Share Posted August 17, 2010 Oops copied the wrong problem sorry. function Search($keyword,$subject,$grade,$search_by) { $user = SQL_User(); $pass = SQL_Pass(); $dbname = SQL_DB(); $connection = mysql_connect('localhost',$user,$pass); mysql_select_db($dbname , $connection); $search_term = mysql_real_escape_string($search_term); $sql = "SELECT * FROM Notes WHERE Keywords LIKE '%$search_term%'"; if($subject == 'NO') { } else { $sql .= " AND Subject='$subject'"; } if($grade == 'NO') { } else { $sql .= " AND Grade='$grade'"; } if($sort_by == 'NO') { } elseif($sort_by == 'RATING') { $sql .= " ORDER BY Rating DESC"; } elseif($sort_by == 'VIEWS') { $sql .= " ORDER BY Views DESC"; } else { } $query = mysql_query($sql , $connection); while($arr = mysql_fetch_array($query)) { $title = file_get_contents('notes/' . $arr['Note_ID'] . '.note'); $title = explode('||TITL_E=',$title); $title = $title[1]; $title2 = explode('=||',$title); $user = SQL_User(); $pass = SQL_Pass(); $dbname = SQL_DB(); $search_term = mysql_real_escape_string($search_term); $connection = mysql_connect('localhost',$user,$pass); mysql_select_db($dbname, $connection); $sql = "SELECT * FROM Notes WHERE Note_ID='$note_id'"; $query = mysql_query($sql , $connection); $query = mysql_fetch_array($query); $title = $query["Title"]; $contents = $title2[1]; $contents2 = wordwrap($contents, 80, ",", true); $contents2 = explode(',',$contents2); $contents2 = $contents2[0]; if($contents2 == $contents) { } else { $contents = $contents . '...'; } $results .= "<a id='search_title' href='view_note.php?id=" . $arr['Note_ID'] . "'>" . $title . "</a><br />"; $results .= "<span id='search_contents'>" . $contents . "</span><br />"; $results .= "<span id='search_author'>" . $arr['Author'] . "</span><br /><br /><br />|*|?|>|"; } return $results; } For some reason I get these errors Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in /home/***/functions.php on line 713 Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in /home/***/functions.php on line 713 I've looked over this many times. I even took the SQL Statement ($sql) and put it through the SQL Command on PHPMyAdmin and replaced the variable with what I am using as a keyword and it works just fine. But I can't figure out quite what is wrong. Line 713 Begins with While($arr... Quote Link to comment https://forums.phpfreaks.com/topic/210896-search-system/#findComment-1100041 Share on other sites More sharing options...
Pikachu2000 Posted August 17, 2010 Share Posted August 17, 2010 Your function parameter is $search_by, but in the query within, you try to use $search_term. Quote Link to comment https://forums.phpfreaks.com/topic/210896-search-system/#findComment-1100055 Share on other sites More sharing options...
pudge1 Posted August 17, 2010 Author Share Posted August 17, 2010 Thanks I can't believe I didn't notice that. However for some reason I still get the same error. Quote Link to comment https://forums.phpfreaks.com/topic/210896-search-system/#findComment-1100067 Share on other sites More sharing options...
Pikachu2000 Posted August 17, 2010 Share Posted August 17, 2010 You'll need to echo the query that's failing to see if it contains the values it should contain. Also, $sort_by is undefined. Quote Link to comment https://forums.phpfreaks.com/topic/210896-search-system/#findComment-1100072 Share on other sites More sharing options...
pudge1 Posted August 17, 2010 Author Share Posted August 17, 2010 Fixed that problem. Echoed it (just like the sql query would appear) and copied and pasted into PHPMyAdmin and it worked fine. Quote Link to comment https://forums.phpfreaks.com/topic/210896-search-system/#findComment-1100078 Share on other sites More sharing options...
Pikachu2000 Posted August 17, 2010 Share Posted August 17, 2010 You echoed it from within the function then pasted it, right? And it works when it isn't enclosed in the function, correct? Quote Link to comment https://forums.phpfreaks.com/topic/210896-search-system/#findComment-1100085 Share on other sites More sharing options...
pudge1 Posted August 17, 2010 Author Share Posted August 17, 2010 Yes that is correct Quote Link to comment https://forums.phpfreaks.com/topic/210896-search-system/#findComment-1100086 Share on other sites More sharing options...
fenway Posted August 17, 2010 Share Posted August 17, 2010 Then you have a php error. Quote Link to comment https://forums.phpfreaks.com/topic/210896-search-system/#findComment-1100349 Share on other sites More sharing options...
pudge1 Posted August 18, 2010 Author Share Posted August 18, 2010 I just got tired of it and completely restarted it and now it works. Thanks to all who helped! Quote Link to comment https://forums.phpfreaks.com/topic/210896-search-system/#findComment-1100571 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.