0

I am trying to code a cron job so if a code in the database and is unused and older then 72 hours it drops the row in the database.

The problem I am having however is that when I am trying to get the array data in a row, so I can run an 'If statement' and then the drop command, when printing the array I get duplicates like as follows

33520891520891do not usedo not use----aaron hattonaaron hattonSunday 8th of September 2013 12:46:20 PMSunday 8th of September 2013 12:46:20 PMUnusedUnused--

My code is as follows

// Set variable for the time
$timenow = date('l jS \of F Y h:i:s A');

    // Start Expired password check and drop function
    function cronexec_expired ($timenow) {

        include('../../config.php');

        // Open up a new MySQLi connection to the MySQL database
        mysql_connect($dbHost, $dbUsername, $dbPassword);
        mysql_select_db($dbTable);

        // Query to check the status of the code input
        $expiry_check = "SELECT * FROM code_log WHERE status='Unused'";

        // Run the query
        $expiry_checkexec = mysql_query($expiry_check);

        while($expiry_possibles = mysql_fetch_array($expiry_checkexec)) {

            foreach ($expiry_possibles as $expiry_possible) {

                print_r ($expiry_possible);

            };

        }


    }

    // Start Redeemed Password check and drop function

// Execute Functions
cronexec_expired ($timenow);

Any help would be really appreciated!

Edit

When removing the 'foreach' and running the following:

print_r ($expiry_possibles);

I get the following

Array ( [0] => 3 [id] => 3 [1] => 520891 [code] => 520891 [2] => do not use [refid] => do not use [3] => - [hostname] => - [4] => - [userip] => - [5] => aaron hatton [creater] => aaron hatton [6] => Sunday 8th of September 2013 12:46:20 PM [timecreated] => Sunday 8th of September 2013 12:46:20 PM [7] => Unused [status] => Unused [8] => - [timeredeemed] => - )

Am I doing something wrong?

1 Answer 1

1

if you mean numeric index in your array output. use mysql_fetch_assoc() instead of mysql_fetch_array()

mysql_fetch_array() essentially returns two arrays one with numeric index, one with associative string index.

Sign up to request clarification or add additional context in comments.

3 Comments

the issue is not the MySQL Query as when run in phpMyAdmin it only shows one row, the issue is the data when put into an array and printed (print_r) duplicates itself as per the example
remove foreach loop and print_r data!!
you mean numeric indexes ? user mysql_fetch_assoc instead of mysql_fetch_array . :)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.