0
I am performing a query in the bank and want to returns more than one query value as I do it?
The structure of my table and the following
Id_idx | name | OUTROS |
Each Id_idx can be repeated up to 3 times I want to count how many rows are returned which is the first part of code and also returns the values of the other columns.
Here will only returns the number of rows.
$char = $pdoG->prepare("SELECT * FROM u_hero WHERE id_idx = :id");
$char->bindValue(":id",$id);
$char->execute();
$chars = $char->rowCount();
return $chars;
While you’re here you return the information.
$char = $pdoG->prepare("SELECT * FROM u_hero WHERE id_idx = :id");
$char->bindValue(":id",$id);
$char->execute();
$chars = $char->fetchAll(PDO::FETCH_OBJ);
return $chars;
How do I unite these return
in a single static function
?
Inside face line has the play id and it can have 3 Hero so id_idx is the play id so it comes up to 3 query with different data however id_idx equal.
– Everton Figueiredo
I think now it will get better from someone help me, I thought that way would be enough apologies.
– Everton Figueiredo
well 3 Heros why can be created up to 3 Heros = 3 rows from the database, I have a common id which is the id_idx want to count and take independent data from each line.
– Everton Figueiredo
Guilherme just want to add $chars = $char->rowCount(); with $chars = $char->fetchAll(PDO::FETCH_OBJ).
– Everton Figueiredo
The last question for me to accept your answer, is there any way I can access the data of each independent line? @Guilherme
– Everton Figueiredo
i did so, foreach ($chars["data"] as $info) { echo $info->id_idx." </br>"; echo $info->name; } my doubt is like selecting the first line and the second line.
– Everton Figueiredo
@Evertonfigueiredo made an example with 2 foreachs, see if this is what you need.
– Guilherme Nascimento
That’s exactly what I’ve been wanting so much thanks and sorry about all the hard work bro.
– Everton Figueiredo
can access the array within the echo $chars['data']->id_idx array;?
– Everton Figueiredo
@Evertonfigueiredo doesn’t because inside data has an index array, which goes type 0, 1, 2, ..., it can do so:
$chars['dados'][0]->id_idx
and the$chars['dados'][1]->id_idx
catch the next.– Guilherme Nascimento