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 6381789
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T02:26:24+00:00 2026-05-25T02:26:24+00:00

I have an array which holds multiple ids’s, and i need to to update

  • 0

I have an array which holds multiple ids’s, and i need to to update multiple columns. i am using MySQL IN() for that. the problem is when i use the query below it works perfectly fine.

public function available($value, $propertyId = array()) {
    $sth = $this->dbh->prepare('UPDATE properties p SET p.status = :status WHERE p.id IN('.implode(',',$propertyId).')');
    $sth->bindParam(':status',$value);
    return $sth->execute();
}

as the above query is not using any placeholders for second argument $propertyId i assume it is wrong way to do so. but when i use either named or unnamed place holder in the query it will update only 1 row. for example the below codes update only one row.

//This will update only one row.
//Using Named Place Holder
public function available($value, $propertyId = array()) {
    $sth = $this->dbh->prepare('UPDATE properties p SET p.status = :status WHERE p.id IN(:propertyId)');
    $sth->bindParam(':status',$value);
    $sth->bindParam(':propertyId', implode(',', $propertyId));
    return $sth->execute();
}

Or

//Using Unnamed Place Holder.
public function available($value, $propertyId = array()) {
    $sth = $this->dbh->prepare('UPDATE properties p SET p.status = ? WHERE p.id IN(?)');
    return $sth->execute(array($value, implode(',', $propertyId)));
}

i tried converting converting the array to a string and assigning it to the variable like below.

public function available($value, $propertyId = array()) {
    $id = implode(',', $propertyId);
    $sth = $this->dbh->prepare('UPDATE properties p SET p.status = ? WHERE p.id IN(?)');
    return $sth->execute(array($value, $id));
}

even that won’t work. what is happening? what am i missing?

thank you

  • 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-05-25T02:26:24+00:00Added an answer on May 25, 2026 at 2:26 am

    You can do something like this, wish it helps.

    public function available($value, $propertyId = array()) {
        $id_placeholders = implode(',', array_fill(0, count($propertyId), '?'));
        $sth = $this->dbh->prepare('UPDATE properties p SET p.status = ? WHERE p.id IN('.$id_placeholders.')');
        return $sth->execute(array_merage(array($value), $propertyId));
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have multiple methods, each of which holds a reference to a single array.
I have a MySQL database table which holds 6 types of records I need
If I have a variant array which holds nothing but simple types, and possible
I have an array in PHP which holds a bunch of unix timestamps. As
I have an array, which holds values like this: $items_pool = Array ( [0]
Let's say I have an array, @theArr, which holds 1,000 or so elements such
I have an array which i need to sort its elements by occurrence then
I have an array which holds a record from a CSV file. Can I
I have an array ( Items ) which holds lots of instances of a
Assume I have an array which holds some struct defined as follows: static struct

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.