Help by returning errors - > Warning: Illegal string offset 'id'

Asked

Viewed 331 times

0

define("HOST","localhost");
define("DB_USER","root");
define("DB_PASS","");
define("DB_NAME","cc_cond");


$conn = mysqli_connect(HOST,DB_USER,DB_PASS,DB_NAME);
ini_set('display_errors', 1);
if(!$conn)
{
    die(mysqli_error());
}


function listar($tabela, $campos="*", $onde=null, $filtro=null, $ordem=null, 
$limite=null) {

global $conn;

$query = "SELECT $campos FROM $tabela";

if ($onde) {            
    $query .= " WHERE $onde";       
}       
elseif ($filtro) {          
    $query .= " WHERE $filtro";     
}

if ($ordem) {           
    $query .= " ORDER BY $ordem";       
}

if ($limite) {      
    $query .= " LIMIT $limite"; 
}

$rs = mysqli_query($conn,$query);

$row = mysqli_fetch_assoc($rs);
$new_array[] = $row;            
return $row;

}

<?php $listagem = listar('sistema'); ?>
   <?php foreach ($listagem as $listar): ?>
   <tr><?php var_dump($listar);?>
   <td><?php echo $listar['id']; ?></td>
   <td><?php echo $listar['cd_sis']; ?></td>
   <td><?php echo $listar['cd_temp']; ?></td>                        
   <td></td>
 <?php  endforeach; ?>
   </tr>

 DUMP!!! Erros -> erros de retorno![![inserir a descrição da imagem aqui][1]][1]
 /var/www/server/projeto-condominio/data/condominio.php:188:string '1' 
 (length=1)
 ERROS ->  Warning: Illegal string offset 'id' in /var/www/server

RETURN ERROR -

1 1 R R 4 4 c c T T 0 0 h h 1 1 1 1 C C 1 1 R R P P 4 4 S S T T 1 1 0 0 what I get instead of recer id 1 name id 2 another name

  • In your database you probably don’t have a column id, check the name, differentiating whether it is uppercase or lowercase

  • is returning this way 1 1 R R 4 4 c c T T 0 0 h 1 1 1 C C 1 1 R R P P 4 4 S S T T 1 1 0 0 wanted to return id 1 id2 name id3 name so on

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.