Reputation: 321
am new to programming. Am trying to display a text after 5 rows from the database. thanks in advance
example:
<row></row>
<row></row>
<row></row>
<row></row>
<row></row>
<p>Hello World</p>
<row></row>
<row></row>
<row></row>
<row></row>
<row></row>
<p>Hello World</p>
<row></row>
<row></row>
<row></row>
<row></row>
<row></row>
my php query:
$post_status= "Published";
$stmt = $mysqli->prepare("SELECT * FROM user_post WHERE status = ? GROUP BY post_id ORDER BY post_id DESC");
$stmt->bind_param('s', $post_status);
$stmt->execute();
$result = $stmt->get_result();
if ($result->num_rows > 0) {
while($row = $result->fetch_assoc()) {
//display the outcome here
}
}
else {
echo "No User Post";
}
The php code works well i just thought of what if i want to show an image or a text after about 5 rows. please help me.
Upvotes: 1
Views: 78
Reputation: 252
$post_status= "Published";
$stmt = $mysqli->prepare("SELECT * FROM user_post WHERE status = ? GROUP BY post_id ORDER BY post_id DESC");
$stmt->bind_param('s', $post_status);
$stmt->execute();
$result = $stmt->get_result();
$counter = 1;
if ($result->num_rows > 0) {
while($row = $result->fetch_assoc()) {
echo '<row>Your row</row>'
if ($counter % 5 == 0) {
echo '<p>Your paragprah</p>';
}
$counter++;
}
}
else {
echo "No User Post";
}
Upvotes: 1