raac Posted February 13, 2006 at 01:02 AM Report Share #13879 Posted February 13, 2006 at 01:02 AM Oi pessoal, tou com um problema, não sei como fazer para ir buscar à base de dados 6 registos ordenados pelo campo data e que o campo mostra seja 1: BD: id | data | mostra 1 | 2006-02-12 12:53:44 | 1 2 | 2006-02-12 12:56:44 | 0 3 | 2006-02-12 11:53:44 | 1 4 | 2006-02-12 12:23:44 | 1 5 | 2006-02-12 13:50:44 | 1 6 | 2006-02-12 10:53:44 | 1 7 | 2006-02-12 12:25:44 | 1 e depois dispolos numa pagina da seguinte maneira: |------| |------| |-----| | 6 | | 3 | | 4 | |------| |------| |-----| |------| |------| |------| | 7 | | 1 | | 5 | |------| |------| |------| | Link to comment Share on other sites More sharing options...
raac Posted February 13, 2006 at 09:02 PM Author Report Share #13934 Posted February 13, 2006 at 09:02 PM ninguem pode dar uma ajudita ??? já consegui fazer o query, agora so nao sei é como por os primeiros 3 registos numa linha e os ultimos 3 noutra linha ? Link to comment Share on other sites More sharing options...
Ped@ntilva Posted February 13, 2006 at 10:48 PM Report Share #13946 Posted February 13, 2006 at 10:48 PM Tentas-te isto? $query = 'SELECT campos FROM tabela WHERE mostra=1 ORDER BY data'; Link to comment Share on other sites More sharing options...
QuickFire Posted February 13, 2006 at 10:51 PM Report Share #13947 Posted February 13, 2006 at 10:51 PM Não sei se ajuda mas por exemplo quando estás a fazer o print dos results da mysql no While, metes do genero While (....) { if (($id == 4) || ($id == 5)) { echo "$id<br>" } else { echo $id } } Qualquer coisa deste modo deve funcionar, mas se quiseres deixa o teu código e depois mostro-te 😉 Link to comment Share on other sites More sharing options...
Ped@ntilva Posted February 13, 2006 at 10:56 PM Report Share #13949 Posted February 13, 2006 at 10:56 PM continuando o meu codigo: $query = 'SELECT campos FROM tabela WHERE mostra=1 ORDER BY data'; $result = mysql_query($query); print '<table>'; while ($linha = mysql_fetch_array( $result )) { print '<tr><td>'; print $linha['campo']; print '</td></tr>'; } Espero k ajude... 😉 Cumps Link to comment Share on other sites More sharing options...
raac Posted February 14, 2006 at 12:34 AM Author Report Share #13952 Posted February 14, 2006 at 12:34 AM desde ja obrigado pela ajuda 😉 mas mesmo assim ainda nao consegui por como pretendia $query="SELECT * from tabelafotos id WHERE destaque = '1' order by data_destaque desc limit 6 "; mysql_connect ($dbserver,$dbuser,$dbpass); mysql_select_db ($dbname); $result = mysql_query ($query) ; print '<table>'; while ($linha = mysql_fetch_array( $result )) { print '<tr><td>'; print $linha['idnome']; print $linha['utilizador']; print '</td></tr>'; } o que queria mesmo era algo deste genero : http://img114.imageshack.us/img114/5391/objectivo3uk.gif Link to comment Share on other sites More sharing options...
Ped@ntilva Posted February 14, 2006 at 03:41 AM Report Share #13954 Posted February 14, 2006 at 03:41 AM Vê se é isto que queres: <?php print '<table>'; for (int $i = 0; $i < 2;$i++){ print '<tr>'; for (int $j = 0; $j < 3;$j++){ $linha = mysql_fetch_array( $result ); print '<td>'.$linha['foto'].'</td>'; //EDIT, inicio $nome[$i] = $linha['nome']; } print '</tr><tr>'; print '<td>'.$nome[0].'</td>'; print '<td>'.$nome[1].'</td>'; print '<td>'.$nome[2].'</td>'; //EDIT, fim print '</tr>'; } print '</table>'; ?> Link to comment Share on other sites More sharing options...
raac Posted February 14, 2006 at 12:56 PM Author Report Share #13965 Posted February 14, 2006 at 12:56 PM mais uma vez obrigado pela ajuda 😉 Pedantilva usando o teu codigo à algo que nao bate certo : $query="SELECT * from tabelafotos id WHERE destaque = '1' order by data_destaque desc limit 6 "; mysql_connect ($dbserver,$dbuser,$dbpass); mysql_select_db ($dbname); $result = mysql_query ($query) ; print '<table>'; for ($i = 0; $i < 2;$i++){ print '<tr>'; for ($j = 0; $j < 3;$j++){ $linha = mysql_fetch_array( $result ); print '<td>'.$linha['idmarca'].'</td>'; //EDIT, inicio $nome[$i] = $linha['idmodelo']; } print '</tr><tr>'; print '<td>'.$nome[0].'</td>'; print '<td>'.$nome[1].'</td>'; print '<td>'.$nome[2].'</td>'; //EDIT, fim print '</tr>'; } print '</table>'; e o resultado é : Audi Renault Aixam 500,4 E Alfa Romeo BMW Citroen 500,4 E C2 quando deveria ser : Audi Renault Aixam A4 19 500,4 E Alfa Romeo BMW Citroen 33 320 C2 ? Link to comment Share on other sites More sharing options...
Ped@ntilva Posted February 14, 2006 at 03:02 PM Report Share #13977 Posted February 14, 2006 at 03:02 PM deixame ver s percebo... keres que apareça as imagens e por baixo a marca e o modelo? Link to comment Share on other sites More sharing options...
raac Posted February 14, 2006 at 03:07 PM Author Report Share #13978 Posted February 14, 2006 at 03:07 PM exactamente 😉 Link to comment Share on other sites More sharing options...
Ped@ntilva Posted February 14, 2006 at 03:11 PM Report Share #13980 Posted February 14, 2006 at 03:11 PM mas estás a fazer com k as imagens apareçam, certo? para marca e modelo em vez de : $nome[$i] = $linha['idmodelo']; põe: $nome[$i] = $linha['idmodelo'].' - '.$linha['modelo']; Link to comment Share on other sites More sharing options...
raac Posted February 14, 2006 at 03:24 PM Author Report Share #13981 Posted February 14, 2006 at 03:24 PM $query="SELECT * from tabelafotos id WHERE destaque = '1' order by data_destaque desc limit 6 "; mysql_connect ($dbserver,$dbuser,$dbpass); mysql_select_db ($dbname); $result = mysql_query ($query) ; print '<table>'; for ($i = 0; $i < 2;$i++){ print '<tr>'; for ($j = 0; $j < 3;$j++){ $linha = mysql_fetch_array( $result ); print '<td> <img border="0" src="foto.php?'.$linha['name2'].'"></td>'; //EDIT, inicio $nome[$i] = $linha['idmarca'].' - '.$linha['idmodelo']; } print '</tr><tr>'; print '<td>'.$nome[0].'</td>'; print '<td>'.$nome[1].'</td>'; print '<td>'.$nome[2].'</td>'; //EDIT, fim print '</tr>'; } print '</table>'; estou a fazer assim e o output nao bate certo nao sei porque 😉 fica sempre assim : Foto Audi Foto Renault Foto Aixam Aixam 500,4 E (aqui fica vazio) (aqui fica vazio) Foto Alfa Romeo Foto BMW Foto Citroen Aixam 500,4 E Citroen C2 (aqui fica vazio) e devia ficar : Foto Audi Foto Renault Foto Aixam Audi A4 Renault 19 Aixam 500,4 E Foto Alfa Romeo Foto BMW Foto Citroen Alfa Romeo 33 BMW 320 Citroen C2 Link to comment Share on other sites More sharing options...
raac Posted February 14, 2006 at 04:58 PM Author Report Share #13986 Posted February 14, 2006 at 04:58 PM ele quando vai buscar a marca e modelo so mostra 2 registos, nao percebo ? Link to comment Share on other sites More sharing options...
Ped@ntilva Posted February 14, 2006 at 05:14 PM Report Share #13987 Posted February 14, 2006 at 05:14 PM Sorry. Tive a testar e tem um pekeno bug: $nome[$i] = $linha['idmarca'].' - '.$linha['idmodelo']; É assim. $nome[$j] = $linha['idmarca'].' - '.$linha['idmodelo']; Link to comment Share on other sites More sharing options...
raac Posted February 14, 2006 at 05:17 PM Author Report Share #13989 Posted February 14, 2006 at 05:17 PM É isso mesmo, obrigadao 😉 Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now