Mir Abzal Ali Mir Abzal Ali - 6 months ago 13
PHP Question

How to stop creating new line no data fetch in array

When I

echo
$cia or $grind, it print all rows the variable have but problem is, there are a blank row in each variable at the end. How do stop creating blank while no data fetch in array.

$cia ="";
$grind = "";

while($data = mysql_fetch_array($sdata) ){
if($data["cia"]){
$cia .= $data["cia"] . "\r\n";
}
if($data["grind"]){
$grind.= $data["grind"] . "\r\n";
}
}


echo $cia;
output:

---------------------
|LEAVE EXT UNGLUED |
---------------------
|1/8 PUFF CV/EXT TOE|
---------------------
|MET PADS BOTH |
---------------------
| |
---------------------

Answer

You need rtrim() extra characters:

$grind = rtrim($grind);

All:

$cia ="";
$grind = "";

while($data = mysql_fetch_array($sdata) ){
    if($data["cia"]){
        $cia .= $data["cia"] . "\r\n";
    }
    if($data["grind"]){
        $grind.= $data["grind"] . "\r\n";
    }
}
$grind = rtrim($grind);
$cia = rtrim($cia);