0
Good night,
I have a query to two tables where I want the second table to return all 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 get back all the data from the establishments table and return me the data that is associated with the establishment id of the establishments table.
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 ;
Table establishments
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 for $_REQUEST variable
Only the code does not. Please post the structure of each table and its respective contents. Also post one
print_r()
andarray_dump
of $_REQUEST after setting it to $row_change– Olimon F.
What happens to me now and that it lists all the respective data of the table categories_establishments with the same id of the table establishments but repeats the content I will put the structure
– César Sousa