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

Link to comment
Share on other sites

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.

 

Link to comment
Share on other sites

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?

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.