Jump to content

[SOLVED] PHP very easy script help


Padgoi

Recommended Posts

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.

Link to comment
https://forums.phpfreaks.com/topic/135999-solved-php-very-easy-script-help/
Share on other sites

<?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

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.

 

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?

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.