Like i have this on my database: tA--------tB lewbr - blabla1 lewbr - blabla2 lewbr - blabla3 blabla1 - lewbr blabla2 - lewbr blabla3 - lewbr send message to player who send the command /codetest> blabla1, blabla2, blabla3 I am trying to do that whit this code: PHP: if(strtolower($args[0]) == "codetest") { $msg = null; foreach($this->LISTTEST($player) as $test => $p) { if($test == 'p2') { $msg .= "$p\n "; return true; } return true; } $sender->sendMessage("§cList:\n $msg"); return true; }public function LISTTEST($tA) { $a = $this->plugin->provider->db->query("SELECT * FROM list_player WHERE tA='$tA'"); $b = mysqli_fetch_assoc($a); return $b; } but when i test i just receive the message (List: ) Why?
Start debugging! For example you can var_dump() `$b` or `$this->LISTTEST($player)` to check you are getting the expected results.
Now it return just 1 name i want to return all names of tA example: List from LewBr: blabla1, blabla2, blabla3 i just do /listf and returns: List from LewBr: blabla1, only...
Your foreach loop contains not one, but two 'return true' statements, so obviously you could only ever get the first item of the array returned by LISTTEST() into $msg, although I can't see how you'd ever have got to sendMessage() unless the result of LISTTEST() is null... but then you haven't posted all the code, as the top half of what you posted doesn't even appear to be in a function. Anyway, delete those two 'return true;' and it should work.
Nope, i have deleted and still get just one player, look how its the database: i need to get blabla1 and blabla2 from LewBr and i have removed the returns and set to false, but still getint just one..
Then remove the return statements in the loop. They not only break the loop, but also the whole function it's being called in aside from returning a value. http://php.net/manual/en/function.return.php
Are you sure? It's ALPHA-9 and i think if i remove return on a command event the command doesn't works.. Look: PHP: 28.10 16:19:35 [Server] INFO string(8) "blabla128.10 16:19:35 [Server] INFO " Code: PHP: $msg = null; foreach($this->LISTTEST($player) as $friend => $p) { if($friend == 'p2') { $msg .= "$p\n "; } } $sender->sendMessage("Test: $msg"); var_dump($msg);
Deam i have posted on stackoverflow and none work's.. https://stackoverflow.com/questions...6993290?noredirect=1#comment80933177_46993290
If that code is in a function which must return a boolean, then you will need a 'return true;', or false depending, after the var_dump(), but at the risk of repeating myself... you've only posted snippets of the code, and this is not a PHP forum. Also you should read this http://php.net/manual/en/mysqli-result.fetch-assoc.php, the important part being 'fetched row' in the explanation below: