Daimler Posted July 22, 2010 Share Posted July 22, 2010 I installed a script and when i go to administration > languages i receive the fallowing error: Fatal error: Call to a member function fetch_assoc() on a non-object in /home/site/public_html/admin/inc/fnc.lang_search.php on line 83 on line 83 i have this: while ($row = $res->fetch_assoc()) Any ideeas please ? Quote Link to comment https://forums.phpfreaks.com/topic/208542-fetch_assoc-error/ Share on other sites More sharing options...
bh Posted July 22, 2010 Share Posted July 22, 2010 Hi, Post your code. The error message says that your $res is not an object. Quote Link to comment https://forums.phpfreaks.com/topic/208542-fetch_assoc-error/#findComment-1089588 Share on other sites More sharing options...
Daimler Posted July 22, 2010 Author Share Posted July 22, 2010 This is the all code: <?php function searchLangKeys($phrase, $search_key, $search_value) { $_search = array( '%', '_', '*' ); $_replace = array( '\\%', '\\_', '%' ); $_phrase = str_replace( $_search, $_replace, ' '.mysql_real_escape_string( trim( $phrase ) ).' ' ); $_phrase = str_replace( ' ', '%', $_phrase ); $_where_definition = array(); if( $search_key ) $_where[] = '`key` LIKE ?phrase'; if( $search_value ) $_where[] = '`value` LIKE ?phrase'; $_where_definition = empty( $_where ) ? '1' : implode( ' OR ', $_where ); $def_lang = SK_Config::section('languages')->get('default_lang_id'); $query = sql_placeholder( "SELECT `section` , `parent_section_id`, `lang_section_id`, `".TBL_LANG_KEY."`.`lang_key_id`, `key`, `value` FROM `".TBL_LANG_SECTION."` LEFT JOIN `".TBL_LANG_KEY."` USING(`lang_section_id`) LEFT JOIN `".TBL_LANG_VALUE."` USING(`lang_key_id`) WHERE (".$_where_definition.")", array( 'phrase' => $_phrase ) ); $keys = array(); $res = SK_MySQL::query($query); while ($row = $res->fetch_assoc()) { $path = ''; if ($row['parent_section_id'] != 0) { $path = $row['section']; $parent_sect = $row['parent_section_id']; do { $query = sql_placeholder( "SELECT `parent_section_id`, `section`, `lang_section_id`, `".TBL_LANG_KEY."`.`lang_key_id`, `key` FROM `".TBL_LANG_SECTION."` LEFT JOIN `".TBL_LANG_KEY."` USING(`lang_section_id`) WHERE `lang_section_id` = ?", $parent_sect ); $parent = SK_MySQL::query($query)->fetch_assoc(); $parent_sect = $parent['parent_section_id']; $end = strlen($path) == 0 ? "" : "." . $path; $path = $parent['section'] . $end; } while ( $parent_sect != 0); $row['path'] = $path; } else $row['path'] = $row['section']; $keys[] = $row; } return $keys; } function getMissingLabels($lang_id) { $languages_num = count(SK_LanguageEdit::getLanguages()); $missing_labels = MySQL::FetchArray( "SELECT `lang_key_id` FROM `".TBL_LANG_KEY."` WHERE `lang_key_id` NOT IN (SELECT `lang_key_id` from `".TBL_LANG_VALUE."` WHERE `lang_id`=".$lang_id." AND `value` != '')"); if (is_array($missing_labels)) { foreach( $missing_labels as $id => $num ) { $query = "SELECT `section` , `parent_section_id`, `lang_section_id`, `".TBL_LANG_KEY."`.`lang_key_id`, `key`, `value` FROM `".TBL_LANG_SECTION."` LEFT JOIN `".TBL_LANG_KEY."` USING(`lang_section_id`) LEFT JOIN `".TBL_LANG_VALUE."` USING(`lang_key_id`) WHERE `lang_key_id`=".$num['lang_key_id']." GROUP BY `lang_key_id`"; $res = SK_MySQL::query($query); while ($row = $res->fetch_assoc()) { $path = ''; if ($row['parent_section_id'] != 0) { $path = $row['section']; $parent_sect = $row['parent_section_id']; do { $query = "SELECT `parent_section_id`, `section`, `lang_section_id`, `".TBL_LANG_KEY."`.`lang_key_id`, `key` FROM `".TBL_LANG_SECTION."` LEFT JOIN `".TBL_LANG_KEY."` USING(`lang_section_id`) WHERE `lang_section_id` =" . $parent_sect ; $parent = SK_MySQL::query($query)->fetch_assoc(); $parent_sect = $parent['parent_section_id']; $end = strlen($path) == 0 ? "" : "." . $path; $path = $parent['section'] . $end; } while ( $parent_sect != 0); $row['path'] = $path; } else $row['path'] = $row['section']; $keys['labels'][] = $row; } } $keys['total'] = count($keys['labels']); } else { $keys = array(); $keys['total'] = 0; } return $keys; } Quote Link to comment https://forums.phpfreaks.com/topic/208542-fetch_assoc-error/#findComment-1089590 Share on other sites More sharing options...
bh Posted July 22, 2010 Share Posted July 22, 2010 Check your $res variable, probably your query(*) has an error. * $res = SK_MySQL::query($query); Debug your query with simple constants example in phpMyAdmin. Quote Link to comment https://forums.phpfreaks.com/topic/208542-fetch_assoc-error/#findComment-1089592 Share on other sites More sharing options...
Daimler Posted July 22, 2010 Author Share Posted July 22, 2010 can you please be more specific ? i am a very beginner in php thank you very much for your time Quote Link to comment https://forums.phpfreaks.com/topic/208542-fetch_assoc-error/#findComment-1089595 Share on other sites More sharing options...
bh Posted July 22, 2010 Share Posted July 22, 2010 One of your query probably wrong: $query = sql_placeholder( "SELECT `section` , `parent_section_id`, `lang_section_id`, `".TBL_LANG_KEY."`.`lang_key_id`, `key`, `value` FROM `".TBL_LANG_SECTION."` LEFT JOIN `".TBL_LANG_KEY."` USING(`lang_section_id`) LEFT JOIN `".TBL_LANG_VALUE."` USING(`lang_key_id`) WHERE (".$_where_definition.")", array( 'phrase' => $_phrase ) ); $query = "SELECT `section` , `parent_section_id`, `lang_section_id`, `".TBL_LANG_KEY."`.`lang_key_id`, `key`, `value` FROM `".TBL_LANG_SECTION."` LEFT JOIN `".TBL_LANG_KEY."` USING(`lang_section_id`) LEFT JOIN `".TBL_LANG_VALUE."` USING(`lang_key_id`) WHERE `lang_key_id`=".$num['lang_key_id']." GROUP BY `lang_key_id`"; Try to test it with simple constants. If its good with sample values, than your dynamic php values wrong. Quote Link to comment https://forums.phpfreaks.com/topic/208542-fetch_assoc-error/#findComment-1089596 Share on other sites More sharing options...
Daimler Posted July 22, 2010 Author Share Posted July 22, 2010 Can you please tell me how to test this ? and what is a simple constant ? Quote Link to comment https://forums.phpfreaks.com/topic/208542-fetch_assoc-error/#findComment-1089598 Share on other sites More sharing options...
bh Posted July 22, 2010 Share Posted July 22, 2010 Yeah, subtitue your dynamic variables with constants. E.g change "TBL_LANG_KEY" to "lang_key"... and check in PHP your values, whether good/wrong. E.g your $_where_definition variable is a correct mysql where statement and etc... Quote Link to comment https://forums.phpfreaks.com/topic/208542-fetch_assoc-error/#findComment-1089599 Share on other sites More sharing options...
Daimler Posted July 22, 2010 Author Share Posted July 22, 2010 Hmm i dont think this problem is in script: i installed thos script on my localhost (xampp) and all works fine but not on my webserver. what could this be ? Quote Link to comment https://forums.phpfreaks.com/topic/208542-fetch_assoc-error/#findComment-1089602 Share on other sites More sharing options...
Daimler Posted July 22, 2010 Author Share Posted July 22, 2010 Hey, i changed that TBL_LANG_KEY and others TBL * with lang_key and etc. and i receive this errors now: Warning: MySQL error: Table 'gayland_gay.lang_key' doesn't exist in query: SELECT `lang_key_id` FROM `lang_key` WHERE `lang_key_id` NOT IN (SELECT `lang_key_id` from `lang_value` WHERE `lang_id`=1 AND `value` != '') in /home/gayland/public_html/internals/SK6_inc/class.mysql.php on line 299 Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in /home/gayland/public_html/internals/SK6_inc/class.mysql.php on line 50 Warning: MySQL error: Table 'gayland_gay.lang_key' doesn't exist in query: SELECT `lang_key_id` FROM `lang_key` WHERE `lang_key_id` NOT IN (SELECT `lang_key_id` from `lang_value` WHERE `lang_id`=8 AND `value` != '') in /home/gayland/public_html/internals/SK6_inc/class.mysql.php on line 299 Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in /home/gayland/public_html/internals/SK6_inc/class.mysql.php on line 50 Warning: MySQL error: Table 'gayland_gay.lang_key' doesn't exist in query: SELECT `lang_key_id` FROM `lang_key` WHERE `lang_key_id` NOT IN (SELECT `lang_key_id` from `lang_value` WHERE `lang_id`=13 AND `value` != '') in /home/gayland/public_html/internals/SK6_inc/class.mysql.php on line 299 Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in /home/gayland/public_html/internals/SK6_inc/class.mysql.php on line 50 Warning: MySQL error: Table 'gayland_gay.lang_key' doesn't exist in query: SELECT `lang_key_id` FROM `lang_key` WHERE `lang_key_id` NOT IN (SELECT `lang_key_id` from `lang_value` WHERE `lang_id`=14 AND `value` != '') in /home/gayland/public_html/internals/SK6_inc/class.mysql.php on line 299 Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in /home/gayland/public_html/internals/SK6_inc/class.mysql.php on line 50 Warning: MySQL error: Table 'gayland_gay.lang_key' doesn't exist in query: SELECT `lang_key_id` FROM `lang_key` WHERE `lang_key_id` NOT IN (SELECT `lang_key_id` from `lang_value` WHERE `lang_id`=15 AND `value` != '') in /home/gayland/public_html/internals/SK6_inc/class.mysql.php on line 299 Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in /home/gayland/public_html/internals/SK6_inc/class.mysql.php on line 50 Warning: MySQL error: Table 'gayland_gay.lang_key' doesn't exist in query: SELECT `lang_key_id` FROM `lang_key` WHERE `lang_key_id` NOT IN (SELECT `lang_key_id` from `lang_value` WHERE `lang_id`=16 AND `value` != '') in /home/gayland/public_html/internals/SK6_inc/class.mysql.php on line 299 Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in /home/gayland/public_html/internals/SK6_inc/class.mysql.php on line 50 Warning: MySQL error: Table 'gayland_gay.lang_key' doesn't exist in query: SELECT `lang_key_id` FROM `lang_key` WHERE `lang_key_id` NOT IN (SELECT `lang_key_id` from `lang_value` WHERE `lang_id`=19 AND `value` != '') in /home/gayland/public_html/internals/SK6_inc/class.mysql.php on line 299 Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in /home/gayland/public_html/internals/SK6_inc/class.mysql.php on line 50 Quote Link to comment https://forums.phpfreaks.com/topic/208542-fetch_assoc-error/#findComment-1089605 Share on other sites More sharing options...
bh Posted July 22, 2010 Share Posted July 22, 2010 You dont understood me Change those field names and etc to constants that are correct at all. Quote Link to comment https://forums.phpfreaks.com/topic/208542-fetch_assoc-error/#findComment-1089609 Share on other sites More sharing options...
timvdalen Posted July 22, 2010 Share Posted July 22, 2010 Hmm i dont think this problem is in script: i installed thos script on my localhost (xampp) and all works fine but not on my webserver. what could this be ? Did you also move the database? Because you can't host the php files somewhere else if you don't change the address from localhost to your ip and open some ports Quote Link to comment https://forums.phpfreaks.com/topic/208542-fetch_assoc-error/#findComment-1089613 Share on other sites More sharing options...
Daimler Posted July 22, 2010 Author Share Posted July 22, 2010 ah no..the script is installed separated. on localhost and on webserver Quote Link to comment https://forums.phpfreaks.com/topic/208542-fetch_assoc-error/#findComment-1089618 Share on other sites More sharing options...
Daimler Posted July 22, 2010 Author Share Posted July 22, 2010 bh sure i dont understood you i am a beginner. thanks for being so pactient with me, but were can i see the correct constants? in the phpmyadmin tables ? or ? Quote Link to comment https://forums.phpfreaks.com/topic/208542-fetch_assoc-error/#findComment-1089619 Share on other sites More sharing options...
timvdalen Posted July 23, 2010 Share Posted July 23, 2010 bh sure i dont understood you i am a beginner. thanks for being so pactient with me, but were can i see the correct constants? in the phpmyadmin tables ? or ? Your configuration is wrong. Localhost is your own computer. You installed your site on a webserver, somewhere else. If you tell php to go look for a database on localhost, it will look on the pc that php is installed on, your webserver. You have to put your database on the same pc as the webserver or edit the host to match your own pc (believe me, this can be very hard en frustrating the first few times, do the first thing) Quote Link to comment https://forums.phpfreaks.com/topic/208542-fetch_assoc-error/#findComment-1090011 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.