-2
function DBRead($table, $params = null, $fields = '*'){
    $table  = DB_PREFIX.'_'.$table;
    $params = ($params) ? " {$params}" : null;
    $query  = "SELECT {$fields} FROM {$table}{$params}";
    $result = DBExecute($query);
    if(!mysqli_num_rows($result))
        return false;
    else{
        while ($res = mysqli_fetch_assoc($result)){
            $data[] = $res;
        }
        return $data;
    }
}
$publicacao = DBRead('publicacao');
    foreach ($publicacao as $pl):
    endforeach;
    <?php foreach ($publicacao as $pl): ?>
        <li>
            <h4><a href="#"><?php echo $pl['title']?></a></h4>
            <h5><?php echo $pl['text']?><a href="%">Continue lendo »</a></h5>
        </li>
    <?php endforeach; ?>
    <?php foreach ($publicacao as $pl): ?>
        <li>
            <h4><a href="#"><?php echo $pl['title']?></a></h4>
            <h5><?php echo $pl['text']?><a href="%">Continue lendo »</a></h5>
        </li>
    <?php endforeach; ?>
I put a print_r($publishing) between the line $publishing = Dbread('publishing'); and foreach ($publication as $pl): Result is below:
Array ( [0] => Array ( [id] => 33 [title] => First Title [text] => First Text ) [1] => Array ( [id] => 34 [title] => Second Title [text] => Second Text ) )
Already the print_r($publishing) that I put between the foreach ($publication as $pl): and endforeach; the result is this:
Array ( [0] => Array ( [id] => 33 [title] => First Title [text] => First Text ) [1] => Array ( [id] => 34 [title] => Second Title [text] => Second Text ) ) Array ( [0] => Array ( [id] => 33 [title] => First Title [text] => First Text ) [1] => Array ( [id] => 34 [title] => Second Title [text] => Second Text ) )
In my database I only have 2 records. Because it is duplicated?
Welcome! , because it will print how many times the foreach run... It’s the same as a for if you do($i=0; $i <2; $i++){ print_r($publication); } this is going to run twice, and obviously print_r will be printed 2x but it will depend on how many records your $publication has
– Anderson Henrique
@Andersonhenrique Hello, I have two records. As I solve this, could help me?
– Susi
Take a look at the answer below @Susi
– Anderson Henrique