php - Display paragraph text after 5 rows
Get the solution ↓↓↓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.
Answer
Solution:
$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";
}
Share solution ↓
Additional Information:
Link To Answer People are also looking for solutions of the problem: xmlhttprequest error flutter
Didn't find the answer?
Our community is visited by hundreds of web development professionals every day. Ask your question and get a quick answer for free.
Similar questions
Find the answer in similar questions on our website.
Write quick answer
Do you know the answer to this question? Write a quick response to it. With your help, we will make our community stronger.