Jump to content


Photo

Help with ->


  • Please log in to reply
3 replies to this topic

#1 mtylerb

mtylerb
  • Members
  • PipPipPip
  • Advanced Member
  • 69 posts
  • LocationEdmonton, AB, Canada

Posted 07 October 2006 - 07:37 PM

I have searched around various search engines but with relatively little luck (search engines won't search for ->).  I'm trying to figure out exactly what the symbols -> do.  I'm just trying to fix a random quote module for Mambo.  I've seen it used in phpBB but I didn't really understand it there either.  So, please excuse my thick skull, the file it's used in reads:

<?php
/**
* 
* 
**/

defined( '_VALID_MOS' ) or die( 'Direct Access to this location is not allowed.' );

$database->setQuery("SELECT * FROM mos_quotes");
$quotes = $database->loadObjectList();
$count = count($quotes);
if (!$count)
{
	echo ("No quotes yet entered.");
}
else
{
$id = rand(1,$count);
$quote = $quotes[$id];

?> 
<p>"<?php $quote->quote ?>" -- <?php $quote->author ?></p>
<p>Quote Number <?php $quote->id ?></p>
<?php
}
?>

Currently though the only output I'm getting is:

"" --

Quote Number


I would probably be able to figure it out and fix it relatively easy if I could understand what the -> does.  I understand it has something to do with OOP but it's going right over my head.  I could probably just re-write it to my own whims, but I would rather just keep the coding as close to the original as possible, not to mention my own programming would likely be less efficient then the original was intended to be.
I may be useless, but I'll try anyway!

The name is pronounced Em Tyler Bee,
But just Tyler will do nicely!

#2 redbullmarky

redbullmarky
  • Staff Alumni
  • Advanced Member
  • 2,863 posts
  • LocationBedfordshire, England

Posted 07 October 2006 - 08:04 PM

in php it can have a few uses. for the one you mention, you're right - it involves OOP. to keep it simple, take the class:
<?php
class simpleclass
{
   function add($a, $b)
   {
      $result = $a + $b;

      return $result;
   }
}
?>

using the -> is a way of referencing a method (function) within a class. so:
$test = new simpleclass();
echo $test->add(5,10); // returns 15

from your code, all i can see is that you  maybe missing a few 'echo' statements. so:

<p>"<?php echo $quote->quote ?>" -- <?php echo $quote->author ?></p>
<p>Quote Number <?php echo $quote->id ?></p>

"you have to keep pissing in the wind to learn how to keep your shoes dry..."

I say old chap, that is rather amusing!

#3 mtylerb

mtylerb
  • Members
  • PipPipPip
  • Advanced Member
  • 69 posts
  • LocationEdmonton, AB, Canada

Posted 07 October 2006 - 08:12 PM

LOL.  My friend, you are a genius!  I feel like a royal doofus now.  How did I miss the lack of echo statements.

*Sign*  It was fun.  Got any recommended websites to help with that OOP stuff?
I may be useless, but I'll try anyway!

The name is pronounced Em Tyler Bee,
But just Tyler will do nicely!

#4 redbullmarky

redbullmarky
  • Staff Alumni
  • Advanced Member
  • 2,863 posts
  • LocationBedfordshire, England

Posted 07 October 2006 - 08:26 PM

http://www.devarticl...ramming-in-PHP/ is a good start to get the basics down. Further from that, the best way to learn is to get your hands dirty and look at OOP in action. I personally learnt by downloading a copy of phpBB (and other PHP packages) and looking at the code.

the good thing about OOP is you can keep it as basic or make it as complex as you like. for example, the 'simpleclass' i put down a couple of posts up is a fully working class (albeit not very useful). keep it simple and move from there, as it can get messy (as i'm realising now ... :) )
"you have to keep pissing in the wind to learn how to keep your shoes dry..."

I say old chap, that is rather amusing!




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users