Reputation: 43
When I use a while loop then my result coming like this.
$skin_type_id = '';
while ($res = $query->fetchObject()) {
if (isset($res->skin_type_id) && $res->skin_type_id != '') {
$skin_type_id .= $res->skin_type_id;
}
}
Output: 471112131415174019
I want output like this:
47
11
12
13
14
15
17
40
19
so how can I do this?
Upvotes: 0
Views: 36
Reputation: 8339
while ($res = $query->fetchObject()) {
if (isset($res->skin_type_id) && $res->skin_type_id != '') {
echo $res->skin_type_id."<br>";
}
}
Even this should work. you wont need an array declared for this.
Upvotes: 0
Reputation: 771
Assign the values to unique array keys and then loop foreach of the indices and echo them out with a <br>
tag after it, this allows you to manipulate your $skin_type_id
values before outputting them.
$skin_type_id = [];
while ($res = $query->fetchObject()) {
if (isset($res->skin_type_id) && $res->skin_type_id != '') {
$skin_type_id[] = $res->skin_type_id;
}
}
// do something with your $skin_type_id array which contains integers
foreach ($skin_type_id as $id)
{
echo $id . '<br>';
}
Upvotes: 0
Reputation: 2735
Use <br>
when you print your value.Something like this:
$skin_type_id .= $res->skin_type_id."<br>";
Upvotes: 1