Padgoi Posted December 8, 2008 Share Posted December 8, 2008 Hey guys, sorry, my PHP knowledge is very limited. I have this script but I keep getting a Fatal error: Using $this when not in object context in sidebar_rating.php on line 15 error. I simply wanna pull the information from a dbase (I know how to connect to the dbase) and display it side by side, nothing more. Can anyone give me a little help? Here's the script: $rating = mysql_query( "SELECT m.name, p.ovr FROM ibf_members m, ibf_pfields_content p WHERE m.id = p.member_id ORDER BY p.ovr DESC LIMIT 20" ) or die("SELECT Error: ".mysql_error()); $num_rows = mysql_num_rows($rating); $this->output .= "<table border=1>\n"; while ($get_info = mysql_fetch_row($rating)){ $this->output .= "<tr>\n"; foreach ($get_info as $field) $this->output .= "\t<td><font face=arial size=1/>$field</font></td>\n"; $this->output .= "</tr>\n"; } return $rating; ?> Thanks in advance. Quote Link to comment https://forums.phpfreaks.com/topic/135999-solved-php-very-easy-script-help/ Share on other sites More sharing options...
premiso Posted December 8, 2008 Share Posted December 8, 2008 Show more code. Right there it does not look like you are inside of a class, it looks like you are in a function. You have to be inside of a class for that to work properly. Quote Link to comment https://forums.phpfreaks.com/topic/135999-solved-php-very-easy-script-help/#findComment-709027 Share on other sites More sharing options...
gevans Posted December 8, 2008 Share Posted December 8, 2008 <?php $rating = mysql_query( "SELECT m.name, p.ovr FROM ibf_members m, ibf_pfields_content p WHERE m.id = p.member_id ORDER BY p.ovr DESC LIMIT 20" ) or die("SELECT Error: ".mysql_error()); $num_rows = mysql_num_rows($rating); $output = "<table border=1> "; while ($get_info = mysql_fetch_row($rating)){ $output .= "<tr> "; foreach ($get_info as $field) $output .= " <td><font face=arial size=1/>$field</font></td> "; $output .= "</tr> "; } return $output; ?> $this is a reserved variable for use within classes in php Quote Link to comment https://forums.phpfreaks.com/topic/135999-solved-php-very-easy-script-help/#findComment-709033 Share on other sites More sharing options...
Padgoi Posted December 8, 2008 Author Share Posted December 8, 2008 That's the entire code. Obviously something is wrong, lol. I just want to pull the info from those fields in the query and display it, nothing more. Quote Link to comment https://forums.phpfreaks.com/topic/135999-solved-php-very-easy-script-help/#findComment-709034 Share on other sites More sharing options...
.josh Posted December 8, 2008 Share Posted December 8, 2008 as premiso said, $this refers to the class in which the method/property resides, and you can only use it inside the class like so: class something { var foobar; function blah () { $this->foobar = 'blahblahblah'; // works, because it refers to foobar in this class } } $this->foobar = 'blahblahblah'; // does not work, because 'this' refers to nothing. Quote Link to comment https://forums.phpfreaks.com/topic/135999-solved-php-very-easy-script-help/#findComment-709035 Share on other sites More sharing options...
Padgoi Posted December 8, 2008 Author Share Posted December 8, 2008 Ok, now the web page is blank with this code: $rating = mysql_query( "SELECT m.name, p.ovr FROM ibf_members m, ibf_pfields_content p WHERE m.id = p.member_id ORDER BY p.ovr DESC LIMIT 20" ) or die("SELECT Error: ".mysql_error()); $num_rows = mysql_num_rows($rating); $output = "<table border=1> "; while ($get_info = mysql_fetch_row($rating)){ $output .= "<tr> "; foreach ($get_info as $field) $output .= " <td><font face=arial size=1/>$field</font></td> "; $output .= "</tr> "; } return $output; Any help please? Quote Link to comment https://forums.phpfreaks.com/topic/135999-solved-php-very-easy-script-help/#findComment-709041 Share on other sites More sharing options...
premiso Posted December 8, 2008 Share Posted December 8, 2008 change return $output to echo $output; Quote Link to comment https://forums.phpfreaks.com/topic/135999-solved-php-very-easy-script-help/#findComment-709046 Share on other sites More sharing options...
Padgoi Posted December 8, 2008 Author Share Posted December 8, 2008 Got it. Thanks for the help fellas. Quote Link to comment https://forums.phpfreaks.com/topic/135999-solved-php-very-easy-script-help/#findComment-709048 Share on other sites More sharing options...
gevans Posted December 8, 2008 Share Posted December 8, 2008 Also you may want to close that table; add $output .= "</table>"; after $output .= "</tr>"; Quote Link to comment https://forums.phpfreaks.com/topic/135999-solved-php-very-easy-script-help/#findComment-709054 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.