Good evening,
I have a query to two tables in which I want the second table to return all the data with the id of table 1 but only returns me a table value when there are more than one with the same id. I need to return the data all of the table settings and that returns me the data that is associated with the id of the establishment of the table settings.
Code
if($_REQUEST['valida'] != "ok"){
if($result_alterar = $conexao->prepare("SELECT * FROM estabelecimentos
INNER JOIN categorias_estabelecimentos ON categorias_estabelecimentos.estabelecimento_id = estabelecimentos.id
WHERE estabelecimentos.id = :id ")){
$result_alterar->bindValue(':id', $_POST['id'], PDO::PARAM_INT);
$result_alterar->execute();
if($result_alterar->rowCount() >0 ){
$row_alterar = $result_alterar->fetchAll(PDO::FETCH_ASSOC);
$_REQUEST = $row_alterar; // O REQUEST ASSUME OS VALORES DO REGISTO, ASSIM EVITAMOS TER QUE CRIAR UM FORMULÁRIO INDEPENDENTE PARA AS EDIÇÕES
}
}
}
Table categories_establishments
CREATE TABLE IF NOT EXISTS 'categorias_estabelecimentos' (
'id' int(11) NOT NULL AUTO_INCREMENT,
'estabelecimento_id' int(11) NOT NULL,
'categoria_slug' varchar(250) CHARACTER SET utf8 COLLATE utf8_unicode_ci NOT NULL,
PRIMARY KEY ('id')
) ENGINE=InnoDB DEFAULT CHARSET=utf8 AUTO_INCREMENT=311 ;
Establishments table
CREATE TABLE IF NOT EXISTS 'estabelecimentos' (
'id' int(11) NOT NULL AUTO_INCREMENT,
'titulo' varchar(250) COLLATE utf8_unicode_ci NOT NULL,
'slug' varchar(500) COLLATE utf8_unicode_ci NOT NULL,
'link_facebook' varchar(250) COLLATE utf8_unicode_ci NOT NULL,
'link_mapa' text COLLATE utf8_unicode_ci NOT NULL,
'distritos' varchar(255) COLLATE utf8_unicode_ci NOT NULL,
'concelhos' varchar(255) COLLATE utf8_unicode_ci NOT NULL,
'morada' varchar(250) COLLATE utf8_unicode_ci NOT NULL,
'contacto' varchar(250) COLLATE utf8_unicode_ci NOT NULL,
'int_preco' varchar(255) COLLATE utf8_unicode_ci NOT NULL,
'link_site' varchar(255) COLLATE utf8_unicode_ci NOT NULL,
'introducao' text COLLATE utf8_unicode_ci NOT NULL,
'servicos' varchar(500) COLLATE utf8_unicode_ci NOT NULL,
'descricao' varchar(500) COLLATE utf8_unicode_ci NOT NULL,
'keywords' varchar(500) COLLATE utf8_unicode_ci NOT NULL,
'keywords_pesquisa' varchar(500) COLLATE utf8_unicode_ci NOT NULL,
'google_verification' varchar(500) COLLATE utf8_unicode_ci NOT NULL,
'activo' tinyint(1) NOT NULL,
'pos' bigint(20) NOT NULL,
PRIMARY KEY ('id')
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci AUTO_INCREMENT=211 ;
Var Dump of variable $ _REQUEST