elkidogz Posted August 18, 2007 Share Posted August 18, 2007 ok, I'm going to have a select on two different tables, the difference i need to insert to a third, I can load the two up as arrays, but now i need compare the two arrays, and have the output entered into a third array so i can enter that one back into a table... suggestions? array 1 Touched files (select few from a HUGE of 5,000+ files) array 2 all files (from same folder) array 3 difference between the two Quote Link to comment Share on other sites More sharing options...
marcus Posted August 18, 2007 Share Posted August 18, 2007 <?php $array1 = array("a" => "green", "red", "blue", "red"); $array2 = array("b" => "green", "yellow", "red"); $result = array_diff($array1, $array2); print_r($result); ?> http://us.php.net/array_diff Quote Link to comment Share on other sites More sharing options...
elkidogz Posted August 18, 2007 Author Share Posted August 18, 2007 tyvm Quote Link to comment Share on other sites More sharing options...
elkidogz Posted August 18, 2007 Author Share Posted August 18, 2007 <?php function insertarray($arrayName) { foreach ($arrayName as $arrayElement) { if ($arrayElement != '.' && $arrayElement != '..')// don't want . and .. in array just file names { $con = mysql_connect("my info"); if (!$con) { die('Could not connect: ' . mysql_error()); } mysql_select_db("DOH ", $con); $query="INSERT INTO notadded (notinfilename) VALUES ('$arrayElement')"; $result = mysql_query($query); echo "File:".$arrayElement." was added to the table. <br>"; } } } $files = scandir("allPICS",0); insertarray($files); ?> Sorry but now, i'm having issues with this insert line, basically it only inserts 30 at a time, how can i make it continue? with a counter while loop or something? make it sleep? please help there are roughly 3000-5000 records in this folder all of them need to go into a table so i can compare them . Quote Link to comment Share on other sites More sharing options...
marcus Posted August 18, 2007 Share Posted August 18, 2007 Do this: function insertarray($arrayName = array() { if that doesn't work remove the semi-colon Quote Link to comment Share on other sites More sharing options...
Psycho Posted August 18, 2007 Share Posted August 18, 2007 Wait a minute. Why don't you just do a single query that will give you the difference? Quote Link to comment Share on other sites More sharing options...
elkidogz Posted August 18, 2007 Author Share Posted August 18, 2007 because i have one table where people are going to be working on these files that will constantly be added to the folder, it never shrinks, it only gets bigger... the first table is the work done table they are adding information about a picture to a table that has the file name, like a title, notes, etc... the second table is just a dump of the files that are in the folder. a third table is being generated so that i can display the pictures that are in the folder but don't have any information on them yet... <?php function insertarray($arrayName) { foreach ($arrayName as $arrayElement) { if ($arrayElement != '.' && $arrayElement != '..')// don't want . and .. in array just file names { $con = mysql_connect("my info"); if (!$con) { die('Could not connect: ' . mysql_error()); } mysql_select_db("DOH ", $con); $query="INSERT INTO notadded (notinfilename) VALUES ('$arrayElement')"; $result = mysql_query($query); echo "File:".$arrayElement." was added to the table. <br>"; } } } function comparearrays() { $query1="SELECT notinfilename FROM notadded"; $result1 = mysql_query($query1); $query2="SELECT fileName FROM pictures"; $result2 = mysql_query($query1); $result = array_diff($result1, $result2); $query="INSERT INTO tobeadded (tobeaddedfilename) VALUES ('$result')"; return($result); } $files = scandir("allPICS",0); insertarray($files); comparearrays(); printr $result; //wanna see the results ?> Quote Link to comment Share on other sites More sharing options...
elkidogz Posted August 18, 2007 Author Share Posted August 18, 2007 Never mind the above code... i've updated it since then... <?php include('Gallery.php'); function insertarray($arrayName) { $con = mysql_connect("no no"); if (!$con) { die('Could not connect: ' . mysql_error()); } mysql_select_db("nope", $con); $cleartable="TRUNCATE TABLE `notadded`"; //clears table notadded $doitnow=mysql_query($cleartable); foreach ($arrayName as $arrayElement)//rebuilds table notadded { if ($arrayElement != '.' && $arrayElement != '..')// don't want . and .. in array just file names { $query="INSERT INTO notadded (notinfilename) VALUES ('$arrayElement')"; $result = mysql_query($query); echo "File:".$arrayElement." was added to the table notadded. <br>"; } } } function comparearrays() { $con = mysql_connect("no no"); if (!$con) { die('Could not connect: ' . mysql_error()); } mysql_select_db("nope", $con); $cleartable="TRUNCATE TABLE `tobeadded`"; //clears table tobeadded $doitnow=mysql_query($cleartable); $query1="SELECT notinfilename FROM notadded"; $result1 = mysql_query($query1); $query2="SELECT fileName FROM pictures"; $result2 = mysql_query($query1); $result = array_diff($result1, $result2); foreach ($result as $arrayElement)//rebuilds table tobeadded { $query="INSERT INTO tobeadded (tobeaddedfilename) VALUES ('$arrayElement')"; $doit = mysql_query($query); echo "File:".$arrayElement." was added to table tobeadded"; } echo "done"; } $files = scandir("allPICS",0); insertarray($files); comparearrays(); mysql_close($con) ?> it goes into both functions, but it only performs the first ones insert am i not doing the arrays right?... what's going on here? 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.