Jump to content

[SOLVED] debug please


elkidogz

Recommended Posts

<?php
function comparearrays($array)
{

      $con = mysql_connect("nope");
      if (!$con)
            {
                  die('Could not connect: ' . mysql_error());
            }
            mysql_select_db("nope", $con);

      $query2="SELECT fileName FROM pictures";
      $result2 = mysql_query($query2);

      $result = array_diff($array, $result2);
      foreach ($result as $arrayElement)//rebuilds table notadded
            {
                  $query="INSERT INTO tobeadded (tobeaddedfilename) VALUES ('$arrayElement')";
                  $doit = mysql_query($query);
                  echo "File:".$arrayElement." was added to table tobeadded";
            }
      echo "function comparearrays is complete.";
}
$files = scandir("allPICS",0);

comparearrays($files);

?>

 

basically i want to see that it gets into the foreach loop, which it isn't right now... i think it's messing up on the arrays (the bane of my existence is arrays) it runs it's part and completes. any advice?

Link to comment
https://forums.phpfreaks.com/topic/65622-solved-debug-please/
Share on other sites

so it should be like this?

 

<?php
function comparearrays($array = array()
{

      $con = mysql_connect("nope");
      if (!$con)
            {
                  die('Could not connect: ' . mysql_error());
            }
            mysql_select_db("nope", $con);

      $query2="SELECT fileName FROM pictures";
      $result2 = mysql_query($query2);

      $result = array_diff($array, $result2);
      foreach ($result as $arrayElement)//rebuilds table notadded
            {
                  $query="INSERT INTO tobeadded (tobeaddedfilename) VALUES ('$arrayElement')";
                  $doit = mysql_query($query);
                  echo "File:".$arrayElement." was added to table tobeadded";
            }
      echo "function comparearrays is complete.";
}
$files = scandir("allPICS",0);

comparearrays($files);

?>

 

basically i want to see that it gets into the foreach loop, which it isn't right now... i think it's messing up on the arrays (the bane of my existence is arrays) it runs it's part and completes. any advice?

Link to comment
https://forums.phpfreaks.com/topic/65622-solved-debug-please/#findComment-327695
Share on other sites

This function works fine. What i don't get is that the other one is basically doing the same thing, it has three arrays the first is provided, second is from a select, third is the difference of those two arrays... and then just insert it.

 

<?php 
function insertarray($arrayName)
{
      $con = mysql_connect("nope");
      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>";
                        }
             }
      echo"function insertarray is complete.<br>";
}?>

Link to comment
https://forums.phpfreaks.com/topic/65622-solved-debug-please/#findComment-327707
Share on other sites

yes, it's an array of all the files in a given folder, my last post had a function that inserts to a table off that, then i use that same list to compare again to a second table.

 

<?php $files = scandir("allPICS",0);?>

output

[177] => Copy of DSCN1966.jpg [178] => Copy of DSCN1967.jpg [179] => Copy of DSCN1975.jpg [180] => Copy of DSCN1976.jpg [181] => Copy of DSCN3550.jpg [182] => Copy of DSCN3561.jpg [183] => DSCN0005.jpg [184] => DSCN0006.jpg [185] => DSCN0007.jpg [186] => DSCN0008.jpg [187] => DSCN0009.jpg [188] => DSCN0010.jpg [189] => DSCN0011.jpg [190] => DSCN0012.jpg [191] => DSCN0013.jpg [192] => DSCN0014.jpg [193] => DSCN0015.jpg [194] => DSCN0016.jpg [195] => DSCN0017.jpg [196] => DSCN0018.jpg [197] => DSCN0019.jpg [198] => DSCN0020.jpg [199] => DSCN0021.jpg [200] => DSCN0022.jpg [201] => DSCN0023.jpg [202] => DSCN0024.jpg [203] => DSCN0025.jpg [204] => DSCN0026.jpg [205] => DSCN0028.jpg [206] => DSCN0037.jpg [207] => DSCN0038.jpg [208] => DSCN0039.jpg [209] => DSCN0042.jpg [210] => DSCN0043.jpg [211] => DSCN0044.jpg [212] => DSCN0045.jpg [213] => DSCN0046.jpg [214] => DSCN0047.jpg

Link to comment
https://forums.phpfreaks.com/topic/65622-solved-debug-please/#findComment-327713
Share on other sites

$array is what the function gets it's the folders directory

 

<?php 

$files = scandir("allPICS",0);
comparearrays($files); ?>

 

this generates an array of file names (scroll up for an example of the values) inside the function its a variable called $array

 

latest code revision

<?php
function comparearrays($array)
{
      //$cleartables="TRUNCATE TABLE `tobeadded`"; //clears table notadded
      //$doitnow2=mysql_query($cleartables);

      //$query1="SELECT notinfilename FROM notadded";
      //$result1 = mysql_query($query1);
      //$array=mysql_fetch_array($result1);
      print_r($array);

      $query2="SELECT fileName FROM pictures";
      $result2 = mysql_query($query2);
      $rows = mysql_fetch_array($result2);
      print_r($rows);

      $result = array_diff($array, $rows);
      foreach ($result as $arrayElement)//rebuilds table notadded
            {
                  $query="INSERT INTO tobeadded (tobeaddedfilename) VALUES ('$arrayElement')";
                  $doit = mysql_query($query);
                  echo "File:".$arrayElement." was added to table tobeadded <br>";
            }
      echo "function comparearrays is complete.";
}
$files = scandir("allPICS",0);
print_r($files); //shows array $files (verify the array exists)
comparearrays($files); //sends $files array to function comparearrays as $array

mysql_close($con)
?>

Link to comment
https://forums.phpfreaks.com/topic/65622-solved-debug-please/#findComment-327741
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.