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 ($ publication) between the line $ publicacao = DBRead ('publication'); 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 ) )
The print_r ($ publication) that I placed between 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. Why is it duplicated?