0

my array item structure look like

title: "",
createdBy: "",
pointerSet:[
    {position: 1, catagoryId: 1, caption: "", imageUrl: ""}
    {position: 1, catagoryId: 1, caption: "", imageUrl: ""}
    {position: 1, catagoryId: 1, caption: "", imageUrl: ""}

]

Now if my URL hit with this item array data then how can i insert pointerSet array item in database.

my database data goes to two table

table one

title: "",
createdBy: "",

then table two

pointerSet:[
    {position: 1, catagoryId: 1, caption: "", imageUrl: ""}
    {position: 1, catagoryId: 1, caption: "", imageUrl: ""}
    {position: 1, catagoryId: 1, caption: "", imageUrl: ""}

]

I am using get method.

in table one i can insert but for table two how can i insert .

$_GET['pointerSet'] = array(
  array(position='', catagoryId='',caption='',imageUrl=''),
  array(position='', catagoryId='',caption='',imageUrl=''),
  array(position='', catagoryId='',caption='',imageUrl='')
);
2
  • Use a loop that inserts a row for each pointer in the pointer set. Commented Oct 20, 2014 at 20:12
  • please give example @Barmar Commented Oct 20, 2014 at 20:17

1 Answer 1

1

Here's how you can do it using a PDO prepared statement

$stmt = $pdo->prepare("INSERT INTO pointerTable (position, categoryid, caption, imageurl) VALUES(:position, :categoryid, :caption, :imageurl)");
foreach ($array['pointerSet'] as $pointer) {
    $stmt->execute($pointer);
}
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.