I'm trying to do a if else depending on the rows that it get back but its not working right i dont know what i'm doing wrong if anyone can give me some insite on what i'm doing wrong would be so much of a help thank you in advance
$dbconnect=mysqli_connect($hostname,$username,$password,$db);
if ($dbconnect->connect_error) {
die("Database connection failed: " . $dbconnect->connect_error);
}
$query=mysqli_query($dbconnect,"SELECT DISTINCT companyname,client_id,feedback,status from review WHERE status=1 ORDER BY RAND() LIMIT 5");
$query3=mysqli_query($dbconnect,"SELECT companyname,client_id,feedback,status from review WHERE status=3");
$rows_get = mysqli_num_rows($query);
if ($rows_get >0) {
{
$row1 = mysqli_fetch_assoc($query);
$row2 = mysqli_fetch_assoc($query3);
$row3 = mysqli_fetch_assoc($query3);
$row4 = mysqli_fetch_assoc($query3);
$row5 = mysqli_fetch_assoc($query3);
}
}else if ($rows_get >1) {
{
$row1 = mysqli_fetch_assoc($query);
$row2 = mysqli_fetch_assoc($query);
$row3 = mysqli_fetch_assoc($query3);
$row4 = mysqli_fetch_assoc($query3);
$row5 = mysqli_fetch_assoc($query3);
}
}else if ($rows_get >2) {
{
$row1 = mysqli_fetch_assoc($query);
$row2 = mysqli_fetch_assoc($query);
$row3 = mysqli_fetch_assoc($query);
$row4 = mysqli_fetch_assoc($query3);
$row5 = mysqli_fetch_assoc($query3);
}
}else if ($rows_get >3) {
{
$row1 = mysqli_fetch_assoc($query);
$row2 = mysqli_fetch_assoc($query);
$row3 = mysqli_fetch_assoc($query);
$row4 = mysqli_fetch_assoc($query);
$row5 = mysqli_fetch_assoc($query3);
}
}else if ($rows_get >4) {
{
$row1 = mysqli_fetch_assoc($query);
$row2 = mysqli_fetch_assoc($query);
$row3 = mysqli_fetch_assoc($query);
$row4 = mysqli_fetch_assoc($query);
$row5 = mysqli_fetch_assoc($query);
}
}else {
$row1 = mysqli_fetch_assoc($query3);
$row2 = mysqli_fetch_assoc($query3);
$row3 = mysqli_fetch_assoc($query3);
$row4 = mysqli_fetch_assoc($query3);
$row5 = mysqli_fetch_assoc($query3);
}
this is the php/html side where the post get pulled to this is where i'm running in to issues
<blockquote class="blockquote" >
<p class="mb-0">"<?php echo $row1['feedback']; ?>"</p>
<footer class="blockquote-footer"><?php echo $row1['client_id']; ?> @ <?php echo $row1['companyname']; ?></footer>
</blockquote>
<blockquote class="blockquote-reverse">
<p class="mb-0">"<?php echo $row2['feedback']; ?>"</p>
<footer class="blockquote-footer"><?php echo $row2['client_id']; ?> @ <?php echo $row2['companyname']; ?></footer>
</blockquote>
<blockquote class="blockquote">
<p class="mb-0">"<?php echo $row3['feedback']; ?>"</p>
<footer class="blockquote-footer"><?php echo $row3['client_id']; ?> @ <?php echo $row['companyname']; ?></footer>
</blockquote>
<blockquote class="blockquote-reverse">
<p class="mb-0">"<?php echo $row4['feedback']; ?>"</p>
<footer class="blockquote-footer"><?php echo $row4['client_id']; ?> @ <?php echo $row4['companyname']; ?></footer>
</blockquote>
<blockquote class="blockquote">
<p class="mb-0">"<?php echo $row5['feedback']; ?>"</p>
<footer class="blockquote-footer"><?php echo $row5['client_id']; ?> @ <?php echo $row5['companyname']; ?></footer>
</blockquote>
</div>
</div>
This is could be a solution for your problem, even if it's a bit tricky:
You can use a while loop instead of using if else, while($row[]=mysqli_fetch_assoc($query)); while($row[]=mysqli_fetch_assoc($query3)); these two will get all your data in an array $row. no need to check conditions as this will get data only if data exists and append with the previous.