S
S
Sergey Konev2020-05-30 12:59:49
PHP
Sergey Konev, 2020-05-30 12:59:49

PHP: how to insert array value in mysql SELECT statement?

Good afternoon!
into the given SELECT query

$query ="SELECT `id`, `name_prod`, `amount`, `summ`, (summ*amount) AS `summ2`, DATE_FORMAT(data_p, '%d.%m.%Y') `data_p`, `status`, `weight`, `metall` FROM $post_name WHERE id IN ($post_id)";

I need to substitute an array of data with values ​​in a separate column, let's call the column amount_2, I tried to use the AS operator, but for some reason it displays the last value of the array in all rows.
I also used the implode() function to translate the array separated by commas, it's useless!
Please help me solve this problem.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Anton Shamanov, 2020-05-30
@SilenceOfWinter

strings must be in quotes - incl. and generally use mysqli/pdo objects "'" . implode("', '", $values) . "'"

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question