Jump to content

A Select Array Not Showing Results


TecTao

Recommended Posts

I am writing a CRON job that will execute daily.  First it will identify from a MySql table the date in a field 'FAPforSale_repost35'  If the date is the today date it will then execute commands to delete photo images in a directory, delete the directory, and finally remove the record from the database.

 

I am on step one which is to build the array of records that match the days date.  When I run the code, there are no errors but I am not getting results even though the records in the test table are set for today.  Below is the select

<?php

 define( "DIR", "../zabp_employee_benefits_processor_filesSm/", true );
 
 require( '../zipconfig.php' );
 require( DIR . 'lib/db.class.php' );
 require_once( $_SERVER['DOCUMENT_ROOT'] . '/_ZABP_merchants/configRecognition.php' );
 require_once( $_SERVER['DOCUMENT_ROOT'] . '/_ZABP_merchants/libRecognition/MailClass.inc' );
 
 
 
$todayRepost35 = date("Y-m-d");
echo $todayRepost35;



function repostEndSelect()
 
      {
        
        global $db;
            
    $this->db = $db;
        
            
     $data = $this->db->searchQuery( "SELECT `FAPforSale_IDnumber`,  `FAPforSale_image1`,  `FAPforSale_image2`,  `FAPforSale_image3`,  `FAPforSale_repost35`  FROM  `FAP_forSaleTest` Where `FAPforSale_repost35` = '$todayRepost35' ");
    
    
         $this->FAPforSale_IDnumber = $data[0]['FAPforSale_IDnumber'];
        $this->FAPforSale_image1 = $data[0]['FAPforSale_image1'];
        $this->FAPforSale_image2 = $data[0]['FAPforSale_image2'];
        $this->FAPforSale_image3 = $data[0]['FAPforSale_image3'];
        $this->FAPforSale_repost35 = $data[0]['FAPforSale_repost35'];
        
        echo $this->FAPforSale_IDnumber;
        echo $this->FAPforSale_image1;
        echo $this->FAPforSale_image2;
        echo $this->FAPforSale_image3;
        echo $this->FAPforSale_repost35;
        
    } // ends function...
        
echo( ' Finished...' );

?>

Thanks in advance for any suggestions or direction.  Chapter two will be when I start testing the commands to delete.

Link to comment
Share on other sites

To clarify, $todayRepost35 is defined outside of your repostEndSelect() function, so repostEndSelect() knows nothing about it since it's not in scope.

 

You need to either define that variable within the function, or pass the variable TO the function like repostEndSelect($todayRepost35)

 

Also, you never call your function so it doesn't get executed. You just define it.

Link to comment
Share on other sites

Thanks CroNiX, I understand your explanation.  I read up on your in scope link and see what you are talking about.  I move the $todayRepost35 into the function.  I'm not clear completely on you point about never calling your function. Is this specific to the echo of the results?  As I work on building this, I wanted to see the row results to verify it is selection the correct rows.

 

If it does,  then I will add the specific commands using the variables from each row.  From what I have read and illustration, I assume that these commands are outside the function, and will loop through each time from the query in the function until completed.  An example is below

<?php
$unLink1 = "/home/zipclick/public_html/specialslocator.com/FAP_Images/$FAPforSale_IDnumber/$FAPforSale_image1";
//echo $unLink2;
unlink($unLink1);

$unLink2 = "/home/zipclick/public_html/specialslocator.com/FAP_Images/$FAPforSale_IDnumber/$FAPforSale_image2";
//echo $unLink2;
unlink($unLink2);

$unLink3 = "/home/zipclick/public_html/specialslocator.com/FAP_Images/$FAPforSale_IDnumber/$FAPforSale_image3";
//echo $unLink2;
unlink($unLink3);

$unLink4 = "/home/zipclick/public_html/specialslocator.com/FAP_Images/$FAPforSale_IDnumber/gick.php";
//echo $unLink2;
unlink($unLink4);

$dir = "/home/zipclick/public_html/specialslocator.com/FAP_Images/$FAPforSale_IDnumber";
rmdir($dir);

mysql_query("DELETE FROM FAP_forSale WHERE
FAPforSale_username = '$con_username' AND FAPforSale_IDnumber = '$FAPforSale_IDnumber' ");
?>
Link to comment
Share on other sites

There was nothing (visible) in your code that actually called repostEndSelect(), so it doesn't get executed.

 

If you had a page that only had:

<?php

echo 'outside function<br>';

function repostEndSelect()
{
  echo 'inside function';
}

and ran it, you would only see "outside function" as the output.

 

If you had

<?php

echo 'outside function<br>';

function repostEndSelect()
{
  echo 'inside function';
}

repostEndSelect(); //calls your function to execute it

Then the output would be:

outside function

inside function

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.