OOP PHP simple question?

In the interest of helping you out, here are some modifications. Please hear this, though: a lot of this might not make sense without a good background in PHP or OOP in general. You should look at @webbiedave's link.

In the interest of helping you out, here are some modifications. Please hear this, though: a lot of this might not make sense without a good background in PHP or OOP in general. You should look at @webbiedave's link.

Class whatever { static function maths() { $tabs = array(); $results = $this->sql->query($requete); while($val = mysql_fetch_array($this)) { $tabs = $val; } return $tabs; } This fixes syntax errors and logic errors (for instance, the creation of the $results variable to hold the SQL query run). I made the maths method static, since there's really no need to instantiate a whatever() object with this current example. Here are some modifications to how this would be used: $results = whatever::maths(); foreacho ($results as $result) { echo $result'average'; echo $result'randomData'; } Since maths() returns something, you need to store that in a variable; simply calling it, as you did previously, doesn't do anything.

That convoluted for loop can be replaced with a foreach loop.

Thank you, obviously I did a lot of confusing things before. I understand very well all your corrected code. Does a static call for Maths() function triggers the __construct of the Whatever class which recieve the database link connection in static?

Thanks for your time ;) – Tristan May 7 '10 at 21:19 Aww, gipped! Lol – webbiedave May 7 '10 at 21:21 @webbiedave, I shall discover a way to send you points and do that pronto. ;) – ABach May 7 '10 at 21:23 @Tristan - not sure I understand your question, but calling a static method inside a class does not call a __construct() function.

If you want to do stuff in a constructor (like establish a database link), get rid of the static keyword in front of the method and instantiate the class in the manner you did previously. – ABach May 7 '10 at 21:24 perfect, you totally get the question since your answer answers it :D Thanks – Tristan May 7 '10 at 21:26.

Please check out PHP OOP basics: php.net/manual/en/language.oop5.basic.php" rel="nofollow">php.net/manual/en/language.oop5.basic.php Edit: Thanks for cleaning up the code. Try something along the lines of: $tabs = array(); while($val = mysql_fetch_assoc($result)) { $tabs = $val; } And: $foo = new whatever(); $tabs = $foo->Maths(); for ($tabs as $tab) { echo $tab'average'; echo $tab'randomData'; } php.net/manual/en/language.oop5.basic.php" rel="nofollow">php.net/manual/en/language.oop5.basic.php.

Ok, i've cleaned up a lot of things. Is that better this way? – Tristan May 7 '10 at 20:29 No - there are still several problems.

For instance, $foo->Maths(); won't do anything and trying to echo Maths->tab... will throw errors. I agree that it is difficult to discern what you're trying to accomplish - can you tell us exactly what you want to do? – ABach May 7 '10 at 20:36 This "answer" should be a comment not an answer.

– evolve May 7 '10 at 20:39 I want to output the result of the SQL query as an array, so I can access it from outside the class like – Tristan May 7 '10 at 20:39 @evolve: Agreed. I edited to make it more an answer. – webbiedave May 7 '10 at 20:45.

I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.

Related Questions