0

Hi,

I'm trying to do a table that shows all the news:

<?PHP
include "db_connect.php";

$sql_destaque = "SELECT data_destaque, imagem_destaque, descricao_destaque FROM destaques ORDER BY cod_destaque ASC";
$executa=mysql_query($sql_destaque,$connect);

$dados = array();
while ($linha = mysql_fetch_array($executa)) $dados[] = $linha;
mysql_free_result($executa);


function add_imglink($linha) {
    echo '<td align="center">';
            echo $linha['data_destaque']."<br/>".$linha['descricao_destaque'];          
			echo '<img src="', $linha['imagem_destaque'], '"><br />';
    echo '</td>';
}


define('NUMERO_COLUNAS', 4);
echo '<table width = 90%  height = 45% align = center>';
for ($i = 0; $i < count($dados); $i += NUMERO_COLUNAS) {
    echo '<tr>';

    for ($col = 0; $col < NUMERO_COLUNAS; $col++) {
        if ($i + $col < count($dados)) add_imglink($dados[$i + $col]);
    }

    echo '</tr>';
}
echo '</table>';

But it gives me error at:

while ($linha = mysql_fetch_array($executa)) $dados[] = $linha;
mysql_free_result($executa);

Can someone help me, please?


Thank You,
PF2G

2
Contributors
7
Replies
8
Views
5 Years
Discussion Span
Last Post by diafol
0
while ($linha = mysql_fetch_array($executa)){
 $dados[] = $linha;
}

Maybe? Otherwise you may have an error in the query - check for number of rows with mysql_num_rows too.

Edited by diafol: n/a

0
while ($linha = mysql_fetch_array($executa)){
 $dados[] = $linha;
}

Maybe? Otherwise you may have an error in the query - check for number of rows with mysql_num_rows too.

It gives me error in:

while ($linha = mysql_fetch_array($executa))

ERROR:

Warning: mysql_fetch_array() expects parameter 1 to be resource, boolean given in C:\wamp\www\site\index.php on line 135

0

As I mentioned, check with mysql_num_rows(). BUT, I suggest you check your query with static values in the phpmyadmin SQL box.

0

As I mentioned, check with mysql_num_rows(). BUT, I suggest you check your query with static values in the phpmyadmin SQL box.

It's working.

Now can you help me with other thing?

Now i want to if it reaches to 5 news, the news number 1 is erased.

Do you understand?

0

no

Let's see...

You have 4 news, right? And then i add another one, that is automatically insert in the website.

Do you understand 'till here?

0

So you just want the last 4, not the first?

If so, use the LIMIT clause:

SELECT ... FROM table ORDER BY id DESC LIMIT 4
This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.