SusieWoosey Posted April 10, 2008 Share Posted April 10, 2008 (php Server version: 4.0.25-standard) (MySQL client version: 4.1.22) Hi all, I am not very clever with .php, but can usually modify something to make it work for me. However, I cannot figure out what this error message is telling me - Fatal error: Call to a member function on a non-object in /home2/andibrad/public_html/16mm/searchmagindex-testnewsearch.php on line 437 Line 437 in my code is - if ($_POST["searchtitle"] || $_POST["searchcontent"]) $search_results = $db->get_results($search_sql); How does the error relate to the php code? What is the error telling me is wrong? Or is it that my php/mysql just doesn't understand it? Suzanne Bradley ps. I can post the whole of the search code if necessary but it is rather long. The code can be seen at http://www.webmastersherpa.com/content/useful-code/32/#c5t_form Link to comment https://forums.phpfreaks.com/topic/100536-cant-make-content-search-work/ Share on other sites More sharing options...
Barand Posted April 10, 2008 Share Posted April 10, 2008 Looks like $db has not been instantiated as an object, or, if it has, the code you posted is inside a function and $db is outside the function scope. Link to comment https://forums.phpfreaks.com/topic/100536-cant-make-content-search-work/#findComment-514292 Share on other sites More sharing options...
SusieWoosey Posted April 11, 2008 Author Share Posted April 11, 2008 Hi Barand, Thank you for replying. Well I think I understand what you say. I've looked at the code, $db is declared as global as far as I can see in a function at the beginning of the code... function prepare_results($search_results) { global $db, $q, $s_array, $searchterm, $exact_term, $exact_term_array; if ($search_results) { foreach ($search_results as $search_result) { $relevancy = 0; $match = 0; $context = ""; this is the first few lines of the function. The only other time $db is used, is at the end of the code, not inside a function, on line 437 where it all falls to pieces and I get the error. $search_sql .= ' )'; // echo "search sql is " . $search_sql . "<br />"; // -------------------------------------------------------------------------------- // --- now do the actual content search... // -------------------------------------------------------------------------------- if ($_POST["searchtitle"] || $_POST["searchcontent"]) $search_results = $db->get_results($search_sql); <-- line 437 // -------------------------------------------------------------------------------- // --- now prepare the results (assign relevancy AND select context text)... // -------------------------------------------------------------------------------- $results_array = prepare_results($search_results); // -------------------------------------------------------------------------------- // --- finally, display the results... // -------------------------------------------------------------------------------- display_results($results_array); this is the last few lines of the code. Sorry if my ramblings are incoherent, I am not a php programmer. Just hoping to sort it out and make it work. Suzanne Bradley Link to comment https://forums.phpfreaks.com/topic/100536-cant-make-content-search-work/#findComment-514602 Share on other sites More sharing options...
Barand Posted April 11, 2008 Share Posted April 11, 2008 Before $db is used, you should have a line with $db = new whateverClassDbIs(); to create a db object Link to comment https://forums.phpfreaks.com/topic/100536-cant-make-content-search-work/#findComment-514608 Share on other sites More sharing options...
SusieWoosey Posted April 11, 2008 Author Share Posted April 11, 2008 Well I don't have any idea what class db is or should be, or anything about classes and objects, well very little anyway. Maybe I'll just strip the code out and look for something else to replace it. Thanks for help, Suzanne. Link to comment https://forums.phpfreaks.com/topic/100536-cant-make-content-search-work/#findComment-514851 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.