Jump to content

[Resolvido] Ajuda listar registos


raac
 Share

Recommended Posts

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

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

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

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

$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

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...

Important Information

By using this site you accept our Terms of Use and Privacy Policy. We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.