Problem with while fetch_assocc and string

0

What I try is to get data from the database to create HTML tags of type option but the problem is that what I need to send is a string and not a array .

The JavaScript that sends the information between HTML and PHP works well if you give it the string .

What I need is to combine the array with the string and send a string . I tried the implode method but it does not work for me. The problem is probably found in the cycle while .

<?php
require('lib.php');

$columna=$_POST['columna'];
$con = new ConectorBD();
$data = " ";
//Intenta la coneccion con la base de datos
if ($con->initConexion('base_de_datos')=='OK') {
//Hace la sentencia sql para consultar de forma correcta
$resultado = $con->consultar([$columna.'_tbl'],[$columna,'id'],'ORDER BY '.$columna.' ASC');

while ($fila = $resultado->fetch_assoc()) {
   $data=$data.'<option value="'.$fila['id'].'">'.$fila[$columna].'</option>';
 }

}
$con->cerrarConexion();
echo json_encode($data);
?>

This is what is in lib.php (creates sql statements correctly)

<?php
class ConectorBD{

function consultar($tablas, $campos, $condicion = ""){
 $sql = "SELECT ";
 $ultima_key = end(array_keys($campos));
 foreach ($campos as $key => $value) {
   $sql .= $value;
   if ($key!=$ultima_key) {
    $sql.=", ";
  }else $sql .=" FROM ";
 }

$ultima_key = end(array_keys($tablas));
foreach ($tablas as $key => $value) {
  $sql .= $value;
  if ($key!=$ultima_key) {
    $sql.=", ";
  }else $sql .= " ";
}

 if ($condicion == "") {
   $sql .= ";";
 }else {
   $sql .= $condicion.";";
 }

 return $this->ejecutarQuery($sql);
 }
}
?>
    
asked by jufrfa 25.07.2017 в 00:10
source

0 answers