php - PDO return empty result o last result Mysql -


please, can tell me i'm doing wrong here?

$unir = "";  $equxflo = $db_con->prepare("select idequipo, concat(equipo.nombre,' ',equipo.modelo,' ',equipo.marca,' ',equipo.serieplaca) flota equipo idusuario = '$idu' order idequipo desc");     $equxflo->execute(); while($row = $equxflo->fetch(pdo::fetch_assoc)){     print_r($row); //show me array     $ht = $row['flota'];     $ie = $row['idequipo'];     $unir = "["."'"."$ht"."'".","."$ie"."]".","; } print_r($unir); //show me la last data 

the problem because of line:

$unir = "["."'"."$ht"."'".","."$ie"."]".",";      ^ missing concatenation operator 

for example show in $unir ['a',3],['a',2],['a',1], show ['a',1] ...

based on requirement, this:

$unir = "";  $equxflo = $db_con->prepare("select idequipo, concat(equipo.nombre,' ',equipo.modelo,' ',equipo.marca,' ',equipo.serieplaca) flota equipo idusuario = :idu order idequipo desc"); $equxflo->bindparam(":idu", $idu);  if ($equxflo->execute()) {     while ($row = $equxflo->fetch(pdo::fetch_assoc)){         $ht = $row['flota'];         $ie = $row['idequipo'];         $unir .= "['" . $ht . "'," . $ie . "],";     }     print_r($unir); } 

better solution:

a better solution declare $unir array , put data in temporary array , push $unir array in each iteration, this:

$unir = array();  $equxflo = $db_con->prepare("select idequipo, concat(equipo.nombre,' ',equipo.modelo,' ',equipo.marca,' ',equipo.serieplaca) flota equipo idusuario = :idu order idequipo desc"); $equxflo->bindparam(':idu', $idu);  if ($equxflo->execute()) {     while ($row = $equxflo->fetch(pdo::fetch_assoc)) {         $tmp_array = array($row['flota'], $row['idequipo']);         $unir[] = $tmp_array;     }     print_r($unir); } 

Comments

Popular posts from this blog

php - Wordpress website dashboard page or post editor content is not showing but front end data is showing properly -

How to get the ip address of VM and use it to configure SSH connection dynamically in Ansible -

javascript - Get parameter of GET request -