I am using PHP PDO and MySQL and would like to convert a MySQL table like this:
|Listing ID | Image ID |
| 1234 | 1 |
| 1234 | 2 |
| 1234 | 3 |
| 1235 | 1 |
| 1235 | 2 |
Into a PHP array like the one below, which I can parse through and insert into another MySQL table using PDO.
[url/path/1234-1:::url/path/1234-2:::url/path/1234-3, url/path/1235-1:::url/path/1234-2]
Here is the code I've written so far. I believe there is an issue with the way the while loops are working as it only picks up the first Listing string and causes an infinite loop.
//Set folder path
$target_path = realpath($_SERVER['DOCUMENT_ROOT']). "\path\uploads\\";
//Query to download all listing IDs in Markers table
$query = $db->query("SELECT * FROM image");
$row = $query->fetch(PDO::FETCH_ASSOC);
while ($row = $query->fetch(PDO::FETCH_ASSOC)) {
$temp = $target_path.$row['L_ListingID']."-".$row['L_ImageID'].".jpg";
//ListingID equals ListingID, append to array
$LI = substr($temp, 40, 8);
while($LI = $LI) {
$temp = $temp.":::".$temp;
echo $temp;
}
}
This is the output which is an infinite loop. Notice that it starts at the second item in the table and hangs there:
C:\path\uploads\40532208-2.jpg:::C:\path\uploads\40532208-2.jpgC:\C:\path\uploads\40532208-2.jpg...ad infinitum