TecTao Posted December 21, 2014 Share Posted December 21, 2014 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. Quote Link to comment https://forums.phpfreaks.com/topic/293216-a-select-array-not-showing-results/ Share on other sites More sharing options...
bsmither Posted December 21, 2014 Share Posted December 21, 2014 I don't see where the function has been made aware of the variable $todayRepost35. I have seen variables made global ($GLOBAL['todayRepost35']) or passing in $todayRepost35 as a function's argument. Quote Link to comment https://forums.phpfreaks.com/topic/293216-a-select-array-not-showing-results/#findComment-1500307 Share on other sites More sharing options...
CroNiX Posted December 22, 2014 Share Posted December 22, 2014 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. Quote Link to comment https://forums.phpfreaks.com/topic/293216-a-select-array-not-showing-results/#findComment-1500385 Share on other sites More sharing options...
TecTao Posted December 22, 2014 Author Share Posted December 22, 2014 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' "); ?> Quote Link to comment https://forums.phpfreaks.com/topic/293216-a-select-array-not-showing-results/#findComment-1500426 Share on other sites More sharing options...
CroNiX Posted December 22, 2014 Share Posted December 22, 2014 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 Quote Link to comment https://forums.phpfreaks.com/topic/293216-a-select-array-not-showing-results/#findComment-1500430 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.