Bunkertor 7 Posted October 15, 2010 Report Share Posted October 15, 2010 Sveiki, Reku uzrakstīju skriptu, kas ver vaļā CSV tabulu, pārvērš to par Array un tad atdala katru elementu. Ideja ir tāda, ka elementi tiek ierakstīti MySQL tabulā. Kad mēģinu izvadīt elementus are "echo" palīdzību, viss strādā. Kad mēģinu tos pašus datus rakstīt iekšā tabulā, tur nonāk tikai Array[0], Array[1] utt. Izmēģinājos gan tā, gan šitā. Būšu pateicīgs par palīdzību! <?php $csv = array(); $file = fopen('file.csv', 'r'); while (($result = fgetcsv($file)) !== false) { $csv[] = $result; } fclose($file); $con = mysql_connect("***","***","***"); if (!$con) { die('Could not connect: ' . mysql_error()); } mysql_select_db("***", $con); for ($row = 1; $row < 3; $row++) { echo $csv[$row][0]." and ".$csv[$row][1]." and ".$csv[$row][2]; echo "<br />"; mysql_query("INSERT INTO *** (ref, title, url) VALUES ('$csv[$row][0]', '$csv[$row][1]', '$csv[$row][2]')"); } echo "thanks"; mysql_close($con); ?> Varbūt man vajadzētu mēģināt Loop iekš Loop? Tomēr īsti nezinu, kā to izdarīt. Quote Link to comment Share on other sites More sharing options...
Леший Posted October 15, 2010 Report Share Posted October 15, 2010 "VALUES ('".$csv[$row][0]."'" Quote Link to comment Share on other sites More sharing options...
Bunkertor 7 Posted October 15, 2010 Author Report Share Posted October 15, 2010 wow! Paldies!!! Quote Link to comment Share on other sites More sharing options...
xPtv45z Posted October 15, 2010 Report Share Posted October 15, 2010 Vai arī mysql_query("INSERT INTO *** (ref, title, url) VALUES ('{$csv[$row][0]}', '{$csv[$row][1]}', '{$csv[$row][2]}')"); Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.