I want to get the name of the columns of a table and their respective records .. Ex: I have the table registers and it has the columns name, login, password and there are 2 records recorded in this table, getting + - like this:
name = alisson / login = admin / password = 123
name = alisson2 / login = admin2 / password = 123
Then I would like to take the name of the columns ( name, login, password ) and get the value of the 2 records that it has in it, 123 )
<?php
protected function ListColumn($table){
$Query = $this->connect->prepare("SHOW COLUMNS FROM {$table}");
$Query->execute();
while($e = $Query->fetch(PDO::FETCH_ASSOC)){
$colunas[] = $e['Field'];
}
return array($colunas);
}
QuerySearch = $this->connect->prepare("SELECT * FROM {$table} WHERE login LIKE '%teste%'");
$QuerySearch->execute();
$Retornados = $QuerySearch->rowCount();
if($Retornados > 0){
while($b = $QuerySearch->fetch(PDO::FETCH_ASSOC)){
foreach($this->ListColumn($table) as $field){
$s[] = $field;
}
}
echo json_encode($s);
}else{
echo json_encode(array('error'=>'Nada foi encontrado com o termo informado.', 'result'=>'0'));
}
?>