目前我有一個數組,如下圖所示,當輸出通過print_r();插入數組在mysql數據庫中使用php
Array ([0] => Array ([0] =>
Sri Chandrasekharendra Saraswathi Viswa Mahavidyalaya
| Kanchipuram, Chennai
[1] =>
Karpaga Vinayaga College of Engineering and Technology
| Kanchipuram, Chennai
[2] =>
SRM University, Chennai - Kattankulathur Campus
| Kattankulathur, Chennai
[3] =>
Saveetha University, Thandalam
| Thandalam, Chennai
[4] =>
B.S. Abdur Rahman Crescent University
| Vandalur, Chennai
[5] =>
P.B. College of Engineering
| Sriperumbudur, Chennai
[6] =>
Saveetha Engineering College
| Thandalam, Chennai
[7] =>
Hindustan University
| Kelambakkam, Chennai
我想插入這個數據到一個表中,每個元素值屬於其各自的字段。
實際上是從網站上抓取數據。我使用了一些regex.all取出的數組包含30個值each.all數組包含了所需的結果,但不能找出如何將它們插入數據庫.even你的方法也NT爲我工作 爲使用循環是:
for ($i=0;$i<30;$i++)
{ $temp1 = $names[1][$i];
$temp2 = $location[2][$i];
$temp3 = $facilities[1][$i];
$temp4 = $reviews[1][$i];
$sql = 'INSERT INTO collegedb (Name,Location,Facilities,Reviews) VALUES ("$temp1","$temp2","$temp3","$temp4")';
$run=mysqli_query($dbconnect,$sql);}
有人可以幫助我理解我應該怎麼處理這個情況? 這裏是完整的代碼http://paste.ubuntu.com/24422534/
變量不會像單引號一樣工作。參數化查詢將更安全/更可靠。 – chris85
你能告訴如何? –
當您的數據不包含任何設施或評論時,您如何期望提取設施和評論? – gview