简体   繁体   中英

Inserting Array into multiple sql fields php

This should be really easy but I am struggling.

Here is my current code

$friends = $facebook->api('/me/friends');
foreach($friends['data'] as $friend) {
$friend_id = $friend['id'];
}
$connections = "INSERT INTO connections (user_id, friend_id) VALUES ('$id', '$friend_id')";

$friend_id = $friend['id']; should be a list of 1000 id's. I want row created in a table for each $friend_id using the same $id

Thanks!

$friends = $facebook->api('/me/friends');
foreach($friends['data'] as $friend) {
$friend_id = $friend['id'];
$connections = "INSERT INTO connections (user_id, friend_id) VALUES ('$id', '$friend_id')";
mysql_query($connections);
}

Like that? You must execute the query once for each row.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM