I want to split up the results of my MySql-query. There will never be more than 50 results in total.
I have a column called 'category' with a number from 1-6 (might get to 10 later on), and I want a subtitle and some white space/line break in front of every category. Some categories won't have any results tho.
To create the subtitles I'd use something similar like what I have on another page too:
if($data['category'] == '1') { $category_title = $mares; }
elseif($data['category'] == '2') { $category_title = $foals; }
elseif($data['category'] == '3') { $category_title = $stallions; }
elseif($data['category'] == '4') { $category_title = $yearlings; }
I tried to work with a loop and $i++ for every number in the column 'category' but that didn't fetch any results somehow. And it probably wasn't the best way to do it performance wise anyway.
Made the loop work so using that for now.
What I use now, without splitting the results, is this:
$results = mysqli_query($connect, "SELECT * FROM list WHERE online = 1 AND sale = 1 ORDER BY YEAR(birthdate) ASC, name");
while ($data = mysqli_fetch_array($results))
{
$sale_name = stripslashes($data['name']);
echo $sale_name;
*and other $data*
}
And what I want to see, is this:
mares
$sale_name
$sale_name
$sale_name
$sale_name
$sale_name
foals
$sale_name
$sale_name
yearlings
$sale_name
$sale_name
$sale_name