acho que estou comendo bola...
o que eu preciso:
tenho uma tabela com os imoveis
id_imovel (+ dados do mesmo)
tenho uma tabela destaque
id_imovel - data
eu preciso trazer na página 9 imóveis e quando não tiver 9 destaques nesta tabela, eu completo com os ultimos imoveis incluídos
meu primeiro sql
$imoveis=mysql_query("SELECT * FROM tabela1, tabela2 where tabela2.dataD = '" . $data_hoje . "' order by id_imovel DESC")
se eu tiver 9 registros aqui, blz.
se não tiver 9 eu devo completar com os ultimos imoveis incluídos, entao faço um segundo sql
$imoveisDestaque2 = mysql_query("SELECT * FROM tabela LIMIT {$total_destaque} ");
(total_destaque) é a conta que fiz 9- os registros exibidos do primeiro sql
conseguria fazer isso em um unico sql?
Vinculo Entre Tabelas
Started By giselelm, 18/12/2013, 11:22
1 reply to this topic
#1
Posted 18/12/2013, 11:22
#2
Posted 18/12/2013, 12:09
$imoveis=mysql_query("SELECT * FROM tabela1, tabela2 where tabela2.dataD = '" . $data_hoje . "' order by id_imovel DESC LIMIT 9")
$cont = 1;
while($row = mysql_fetch_object($imoveis)){
MOSTRA NA PÁGINA
$cont++;
}
if($cont < 9){
$limiteDestaque = 9 - $cont;
$imoveisDestaque2 = mysql_query("SELECT * FROM tabela LIMIT $limiteDestaque ");
while($row = mysql_fetch_object($imoveisDestaque2)){
MOSTRA NA PÁGINA
}
}
$cont = 1;
while($row = mysql_fetch_object($imoveis)){
MOSTRA NA PÁGINA
$cont++;
}
if($cont < 9){
$limiteDestaque = 9 - $cont;
$imoveisDestaque2 = mysql_query("SELECT * FROM tabela LIMIT $limiteDestaque ");
while($row = mysql_fetch_object($imoveisDestaque2)){
MOSTRA NA PÁGINA
}
}
Edição feita por: digo, 18/12/2013, 12:09.
0 user(s) are reading this topic
0 membro(s), 0 visitante(s) e 0 membros anônimo(s)