我有兩個腳本的結果/輸出。如何將簡單的PHP數組插入到MySQL表中?
腳本1結果:
print_r($unit);
OUTPUT =
Array ([0] => http://one.com, [1] => http://two.com, [2] => http://three.com/,)
腳本2結果:
echo $item."<br>";
OUTPUT =
http://one.com,
http://two.com,
http://three.com,
我尷尬未能未能導入任何一個到MySQL表,只有兩個字段:ID和URL 。
//Connect to MySQL...
// Attempt insert query execution
$list=implode($unit);
$sql = "INSERT INTO urls (url) VALUES ('$list')";
if(mysqli_query($conn, $sql)){
echo "Records added successfully.";
} else{
echo "ERROR: Could not able to execute $sql. " . mysqli_error($conn);
}
// Close connection
mysqli_close($conn);
插入件工作,但該代碼插入所有3個網址爲單個字段:
兩個腳本1和2id url
1 http://one.com,http://two.com,http://three.com,
DESIRED MySQL表的結果:
id url
1 http://one.com
2 http://two.com
3 http://three.com
感謝對於你的想法!
'$名單=破滅(「,」,$單位);'試試看。 –
使用「for each」循環 – c4pricorn
@ Fred-ii-:我認爲他希望每條記錄都有一行。 –