0
$ids = ( "1,2,3,4,20") ;
$values =('11,12,13,14');

$stmt   = $conn->prepare("UPDATE Crypto_price SET price=? WHERE id  IN($ids)") ;
$stmt->execute(array($values)) ;
$row = $stmt->rowcount() ;

I want to update price table with the $values the ids work well.when I run my endpoint php file all ids updated to 11

any help?

Barmar
  • 669,327
  • 51
  • 454
  • 560
Alex
  • 1
  • 2
  • Are you saying you want to set 1 to 11, 2 to 12, 3 to 13? Shouldn't you be using a parameter instead of `$id` in your code? I guess otherwise it will just update all id's every time and just happens to update to 11 last – Nick.McDermaid Aug 18 '21 at 04:02
  • @Nick.McDermaid yes i want do that..so how can I do that – Alex Aug 18 '21 at 04:04
  • In this case, you must make different requests to update the id and value pairs. – Sergey K. Aug 18 '21 at 04:05
  • I have 700 rows and I need to update them every 5 min – Alex Aug 18 '21 at 04:07
  • The syntax for that is `SET price = CASE id WHEN 1 THEN 11 WHEN 2 THEN 12 WHEN 3 THEN 13 END` – Barmar Aug 18 '21 at 04:07
  • You have 5 IDs and 4 prices. How is that supposed to work? – Barmar Aug 18 '21 at 04:07
  • 1
    Apply the techniques demonstrated in the provided links. If these pages do not inform you enough, there will be other pages on Stack Overflow to help you. If you still can't resolve this after researching and exhausting your skills, then you are welcome to ask a new question that shows your progress. The new question (if you actually need to ask it) _should_ be more narrow about where you are struggling. – mickmackusa Aug 18 '21 at 04:13

0 Answers0