How to extract data from the database, store it in an array and pass it to an implod in PHP and Mysql?

I am trying to extract from a database query a series of data and these data apart from printing them in a table, I also want to store them in an "implod" to generate a PDF format where the same data will be extracted by means of an "explode" .

To verify the correct operation I have some "text" type inputs where the extraction of the query data should be seen separated and separated by comma, however only the last record of a series of data prints.

Note: As a curious fact in the html table the query is reflected correctly, that is, all data is extracted, but for some reason in the "implod" and the "inputs" the same thing does not happen.

<img src = "https://i.stack.imgur.com/eOGEn.png" alt = "Table html with correct data and dependent on the "implod" with the commented failure "/>

0)
                {
                    while ($ row = mysql_fetch_array ($ re))
                    {
                        // Array demo of products simulating data extraction from a database.
                        $ array_products = array
                        (
                        "units" => array ($ row['cantidad']),
                        "products" => array ($ row['categoria']. ' / '. $ row['subCateg']),
                        "unit_price" => array ($ row['total']),
                        "discount" => array ($ row['descuento'])
                        );
                    

                                           
                        $ x = 0;
                        while ($ x <= count ($ array_products["unidades"]) - one)
                        {
                            threw out
                            "
                                
                            
                            
                            
                            ";
                            $ x ++;
                        }
                    
                
                        // Next the data of the products are saved in variables, separated by commas
                        // which will then be extracted through the explode function when generating the invoice
                        $ units = implode (",", $ array_products["unidades"]);
                        $ products = implode (",", $ array_products["productos"]);
                        $ price_unit = implode (",", $ array_products["precio_unidad"]);
                        $ discount = implode (",", $ array_products["descuento"]);
                        // Next the data of the products will be saved through hidden fields
                    }
                    
                }
            ?>
            
UnitsproductsUnit priceDiscount
". $ array_products["unidades"][$x]. " ". $ array_products["productos"][$x]. " ". $ array_products["precio_unidad"][$x]. "MXN ". $ array_products["descuento"][$x]. "%
<input type = "text" name = "units" value = ""readonly =" readonly ">             <input type = "text" name = "products" value = ""readonly =" readonly ">             <input type = "text" name = "unit_price" value = ""readonly =" readonly ">             <input type = "text" name = "discount" value = ""readonly =" readonly ">