Question and answer is powered by AnsPress.io
Fetch data from MySQL database using foreach. My loops return multi-time but I want to return one time. How can I do?
I am trying with this code:
<?php
foreach ($data as $row) {
echo $row[’value’];
}
?>
Follow this example code, hope it will be helpful for you to return loop one time.
Example code:
<?php
$counter = 1;
$length = count($data);
if ($data) {
foreach ($data as $row) {
if ($counter >1) {
echo ” “;
}else{
echo $row[’value’];
}
$counter++;
}
}
?>