Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9046243
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T11:36:44+00:00 2026-06-16T11:36:44+00:00

I am using PHP PDO and MySQL and would like to convert a MySQL

  • 0

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
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-16T11:36:45+00:00Added an answer on June 16, 2026 at 11:36 am

    while($LI = $LI) causes the infinite loop.

    I guess that is what you want

    $target_path = realpath($_SERVER['DOCUMENT_ROOT']). "\path\uploads\\";
    $query = $db->query("SELECT * FROM image");
    while ($row = $query->fetch(PDO::FETCH_ASSOC)) {
       $temp[] = $row;
    }
    foreach($temp as $i=>$v){
        $line = $v['L_ListingID']."-".$v['L_ImageID'].".jpg";
        $prod[] = $line.($temp[$i] == $temp[$i+1])?":::":",";
    }
    
    echo trim(implode($prod),",");
    

    The code is not tested, but I think that the direction is like there.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am attempting to convert the MySQL table into an array using PHP. Each
Using PHP, MySQL, PDO For logging/debug purposes, I would like to be able to
Using PHP I echo out table rows in a loop like this: <?php /*
I would like to know what query is executed using PHP PDO. I have:
Im using MySQL with PDO PHP scripts to maintain a user database and a
I'm using PDO to insert a record (mysql and php) $stmt->bindParam(':field1', $field1, PDO::PARAM_STR); $stmt->bindParam(':field2',
I'm using PDO in my PHP application. It connects to a MySQL server on
I'm using the PHP PDO's to insert and update values in a table. The
I'd prefer to use native php for Zend configuration. How would I convert this
I'm coding using PHP PDO and MySQL. In that context, can I write a

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.