Single-line save in DB, the result of the PHP variable (WHILE/LOOP) of a MYSQL Query

Asked

Viewed 73 times

1

I have the following problem:

When performing a query, the while result is composed of more than one value, for example:

   $query_sku = mysqli_query($connect, "SELECT t.column_name
        FROM skus AS s
            INNER JOIN table AS t ON t.column_id = s.column_id
                WHERE s.id_sku = '{$id_sku}'");
WHILE($reg = mysqli_fetch_object($query_sku )){
  $variable = $reg->column_name;
echo "<br/">;
}

The result of this query/while is:

BATERIA  
PARA
CÂMERA
CANON
PowerShot ELPH 330 HS

And if I have it saved in the database, it will save a return per line:

inserir a descrição da imagem aqui

When I really want him to come back that way:

BATERIA PARA CÂMERA CANON PowerShot ELPH 330 HS

And save to Database in only one line:

inserir a descrição da imagem aqui

1 answer

0

Changing your code to the following solves the problem?

while($reg = mysqli_fetch_object($query_sku ))
    $variable .= " ".$reg->column_name;

In the variable $variable is the concatenation of all the values of the query, where then just insert this value in the database.

  • Thanks for the reply @João Martins, the problem is that when I do this, it returns me several times the answer: Powershot ELPH 330 HS BATTERY (RECHARGEABLE)Powershot ELPH 330 HS BATTERY (RECHARGEABLE) Camerapowershot ELPH 330 HS BATTERY (RECHARGEABLE) CAMERA CANON

  • The variable does not take all these values, only the last one. If you do echo $variable after the cycle WHILE can confirm that the value is correct.

  • So @Rogériodesájr., managed to solve the problem?

Browser other questions tagged

You are not signed in. Login or sign up in order to post.