I have a query to bring results from my database. It works... until there are more than 2 results that it, then it just repeats some results before adding in new ones.
I know it will be because my query is fairly poor, can anyone advise me?
The idea is
- connect to database with photo links
- get the default user picture as $profile_main
- join the words "photo_" with the default picture number and call it $answer (ex: column 'photo_1' in database)
- now check the database again and get the results for $answer and output all information from that database column.
$result = mysqli_query($con,"SELECT * FROM tbl_photos");
while($row = mysqli_fetch_array($result))
{
$profile_main = $row['default'];
$answer = "photo_" . $profile_main;
$result2 = mysqli_query($con,"SELECT $answer FROM tbl_photos");
while($row = mysqli_fetch_array($result2))
{
echo "<img src=\"" . $row[0] . "\">";
}
}