Hello:
I need some assistance with the following script configuration. The goal is to run a cronjob with my initial script which would run a mysql query and pull some account ids, it then would create an array of those values and through a for() loop execute a second script with each individual value (account id ) passed on to the secondary script. The secondary script needs to perform specific tasks which are totally dependent upon the account id. Below is what I have.
first Script
<?php
//*
$link = mysql_connect('****', '****', '*****');
if(!$link) {
die('Failed to connect to the server: ' . mysql_error());
}
//Select database
$db = mysql_select_db('*****');
if(!$db) {
die("Sorry I am Unable to select database");
}
$get_acctids="select accountid from company_info";
$results = mysql_query($get_acctids) or die(mysql_error());
$new_array[] = $row;
while( $row = mysql_fetch_assoc( $results)){
$acct_data[] = $row['accountid'];
//print_r($acct_data);
}
$key = $acct_data;
//echo "<br /><br />";
//print_r($key);
foreach($key as $value){
$dr[] = "accountid = '$value' "; // Build array of strings
}
/* for testing purpose, uncomment
echo "<br /><br />";
print "<pre>";
print_r($dr);
print "</pre>";
echo "<br /><br />";
*/
function include_get_params($file) {
$parts = explode('?', $file);
if (isset($parts[1])) {
parse_str($parts[1], $output);
foreach ($output as $key => $value) {
$_GET[$key] = $value;
}
}
include($parts[0]);
}
$sql = "select * from company_info WHERE ";
$sql .= implode(' OR ', $dr); // convert to string joined by ' OR ' and add to end of $sql
// Instead of using a loop and running a query for 'Cable Guy'
// and another query for 'John Doe', the following query fetches both rows.
$result = mysql_query($sql);
$numrows=mysql_num_rows($result);
//echo $numrows;
while($row = mysql_fetch_array($result))
{
echo "<br /><br />";
//echo $row['co_name']."--".$row['accountid']. "--".$row['co_website']."<br />";
// echo $row[0]."--".$row[5]. "--".$row['co_website']."<br />";
for ($i=0; $i<1; $i++) {
if (isset($row['accountid']) ) {
//including the secondary script
include_get_params('purge_queueList_daily.php?accountid='.$row['accountid']);
} else {
break;
}
}
//mysql_close($db);
}
?>
Now, secondary script function would be to use each account id and query a corresponding database with the id as the required variable and thus purge a specified table within the script.
Secondary script:
<?php
$club_id =$_GET['accountid'];// This is from the first script and will be required in the included file below (datalogin.php
include 'datalogin.php';
$link = mysql_connect(DB_HOST, DB_USER, DB_PASSWORD);
if(!$link) {
die('Failed to connect to server: ' . mysql_error());
}
//Select database
$db = mysql_select_db(DB_DATABASE);
if(!$db) {
die("Unable to select database");
}
echo $db." <br />";
//echo $db;
$todayis=date("Y-m-d");//date and time
$qry = "DELETE FROM queue_sys where todays_date NOT LIKE '%$todayis%'";// remove players from the list from previous days
$result=mysql_query($qry);
if($result)
{
$message= "<br /><br /><p><font size=5 color=blue>Queue table Has been Purged and Updated!</font>";
}
else
{
$message="Purge failed!";
}
// echo $message;
?>
I'm afraid my logic may be wrong. I'm unable to complete the task of purging the specified table in the secondary script. I would really appreciate some assistance in getting this resolved!
Best,
Mossa