Reputation: 1593
I am new in PHP. I have a code in which i use foreach loop to display data in table of explode function.
Here i have a question
The data in my db is
Here you see After Aatir
there is a blank space. When i use loop to print data
<?php
ini_set('error_reporting', E_ALL);
$servername = "localhost";
$username = "root";
$password = "";
$dbname = "pacra1";
$conn = new mysqli($servername, $username, $password, $dbname);
$sql = "SELECT * FROM `pacra_clients` WHERE `id` = 50";
$conn->multi_query($sql);
$result = $conn->use_result();
echo $conn->error;
$row = $result->fetch_assoc();
$liaison_one = $row['liaison_one'];
$liaison_one_chunks = explode(",", $liaison_one);
echo '<table border="01">';
foreach($liaison_one_chunks as $row){
echo '<tr>';
$row = explode(',',$row);
foreach($row as $cell){
echo '<td>';
echo $cell;
echo '</td>';
}
echo '</tr>';
}
echo '</table>';
?>
The result of my code is
In result you can see that there is a blank cell due to blank space in data.
Is it possible that i can skip blank space which is in my data???
Upvotes: 1
Views: 1625
Reputation: 1241
Try this
foreach($row as $cell){
if ($cell != "" && $cell != null)
{
echo '<td>';
echo $cell;
echo '</td>';
}
}
Upvotes: 1
Reputation: 1063
Yes it is possible. Use continue.
foreach($row as $cell){
if ($cell == "")
continue;
echo '<td>';
echo $cell;
echo '</td>';
}
Upvotes: 2