i am using this code to generate rows depending on the value in the database, I'm sure there is a more efficient way of doing this but I'm unsure how!
if ($empty == 1) {
echo "<li class='col-sm-4'><div class='horse-wrap empty'>Empty</div></li>";
}
if ($empty == 2) {
echo "<li class='col-sm-4'><div class='horse-wrap empty'>Empty</div></li>";
echo "<li class='col-sm-4'><div class='horse-wrap empty'>Empty</div></li>";
}
if ($empty == 3) {
echo "<li class='col-sm-4'><div class='horse-wrap empty'>Empty</div></li>";
echo "<li class='col-sm-4'><div class='horse-wrap empty'>Empty</div></li>";
echo "<li class='col-sm-4'><div class='horse-wrap empty'>Empty</div></li>";
}
if ($empty == 4) {
echo "<li class='col-sm-4'><div class='horse-wrap empty'>Empty</div></li>";
echo "<li class='col-sm-4'><div class='horse-wrap empty'>Empty</div></li>";
echo "<li class='col-sm-4'><div class='horse-wrap empty'>Empty</div></li>";
echo "<li class='col-sm-4'><div class='horse-wrap empty'>Empty</div></li>";
}
You can do it using for loop:
$empty = 5;
$str = '';
for(i=0;$i<$empty;$i++) {
$str .= "<li class='col-sm-4'><div class='horse-wrap empty'>Empty</div></li>";
}
echo $str;
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With