I have a problem with the while loop. So i have this code that inserts feed and multiple files with a specific random code. For example i have this table named 'feed'
ID | FEED | FILE | CODE
---------------------------------------
1 |Test post |uploads/1.jpg | 54231
2 |Test post |uploads/2.jpg | 54231
3 |Test post |uploads/3.jpg | 54231
4 |Test post |uploads/4.jpg | 54231
I need to print the feed only once if the code is repeated, in while loop. Here is my code:
<?php
$connect = mysqli_connect("localhost","root","","test");
// Check connection
if (mysqli_connect_errno())
{
echo "Failed to connect to MySQL: " . mysqli_connect_error();
}
$q = mysqli_query($connect,"SELECT * FROM feed");
$fetch = mysqli_fetch_array($q);
while($fetch = mysqli_fetch_array($q)) {
echo '<div class="post">'.$fetch['feed'].$fetch['file].'</div><br>';
}
?>
The above code outputs:
Test postuploads/1.jpg
Test postuploads/2.jpg
Test postuploads/3.jpg
Test postuploads/4.jpg
I need something that's like this:
Test post uploads/1.jpg / uploads/2.jpg/ uploads/3.jpg/ uploads/4.jpg
How to achieve this? and thanks in advance!