mysql - How to display the multiple records in a line from single column and all the rows using php
Get the solution ↓↓↓Solution:
I would iterate through exploded array:
$sql ="SELECT email FROM email12";
$result = $conn->query($sql);
if ($result->num_rows > 0) {
while($row = $result->fetch_assoc()) {
$a=$row['email'];
$b = explode(',',$a);
foreach($b as $email) {
echo '<pre>'; print_r($email);echo '<pre>';
}
}
}
Answer
Solution:
From the database's perspective, it's not recommended and certainly not a good practice to have data as comma separated list. You should consider your database. Having said that, you should follow the below procedure to achieve the desired result as of now(or for the time being).
Create an empty array(for example,$resultArr
) before the beginning ofwhile
loop. In each iteration ofwhile
loop, email column value and append them to
$resultArr
array. Finally, after coming out of the loop, simply perform operation on the resultant array to display all the records in one line.
$sql ="SELECT email FROM email12";
$result = $conn->query($sql);
if ($result->num_rows > 0) {
$resultArr = array();
while($row = $result->fetch_assoc()) {
$resultArr[] = explode(',',$row['email']);
}
echo implode(',', $resultArr);
}
Share solution ↓
Additional Information:
Link To Answer People are also looking for solutions of the problem: call to a member function update() on null
Didn't find the answer?
Our community is visited by hundreds of web development professionals every day. Ask your question and get a quick answer for free.
Similar questions
Find the answer in similar questions on our website.
Write quick answer
Do you know the answer to this question? Write a quick response to it. With your help, we will make our community stronger.