READ PHP - mysql_fetch_array

1

Hello, I'd like some help with the command below. I'm trying a read in a database table but I can not do while because it only shows the last record.

Note: Using vardump it shows loop normal.

<?
class AppNoticiasDestaque{

    function AppNoticiasDestaque() {
        $verQ = "SELECT * FROM noticias";

        $ver = mysql_query($verQ) or die(mysql_error());
        if(mysql_num_rows($ver) > 0) {

            while($verRow = mysql_fetch_array($ver)) {
            var_dump ($this->AppNoticiasDestaque = $verRow);
    }}
        @mysql_free_result($ver);
    }
}
?>

//resgatando o resultado
<?=$obj->AppNoticiasDestaque['titulo_noticia'] ?>
    
asked by anonymous 14.06.2016 / 05:48

1 answer

1

Hello @Davi, I do not know if I understood correctly what you want to do, but the problem I noticed is the following:

<?php $this->AppNoticiasDestaque = $verRow; ?>

For each time the code passes in the loop you are replacing everything you have saved by the next line, which results in only 1 record. You can resolve this by changing the return of your method to:

<?php $this->AppNoticiasDestaque[] = $verRow; ?>

In order for you to have an array with all the results, you can test using this:

<?
echo "<pre>";
print_r($obj->AppNoticiasDestaque);
?>

I think this will help you.

    
14.06.2016 / 13:39