kouros91
Member
Hi;
I have a issue with a php cron script which must run everyday to change days between now and a limit date
If date as changed, script update all records of the table "table_adhcont" with the new nbjoursavtecheance value.
My code of script is :
The code runs in a php_events of a list or inside an article with sourcerer but i suppose it stops before end of records (12800 records). I don't know how make a compact query which updates all rows with a different value of the field "nbjoursavtecheance" for each row.
I can create an array but i don't know write the query correctly and run this query in cron php script. But i would like it runs automatically every day at 01h00 am.
Perhaps with a temporary table with new values of col of my table and after make an update from ......
It doesn't work with planification cron. Error 500 http
Can you help me ?
Thank you again
Nicolas
I have a issue with a php cron script which must run everyday to change days between now and a limit date
If date as changed, script update all records of the table "table_adhcont" with the new nbjoursavtecheance value.
My code of script is :
PHP:
$db = JFactory::getDbo();
$query = $db->getQuery(true);
$query->select('id,DateMod');
$query->from('table_datemod as c');
$db->setQuery($query);
$rows = $db->loadObjectList();
foreach( $rows as $row )
{
$this_user_datemod = $row->DateMod;
}
$flagmod = 0;
$nowDate = $this_user_datemod;
$thenDate = date("Y-m-d");
if ($nowDate!=$thenDate) {
$flagmod = 1;
$IDinput = 1;
$query = $db->getQuery(true);
$query
-> update('table_datemod AS c')
-> set('datemod ="'.$thenDate.'"')
-> where('c.id = '. (int) $IDinput);
$db->setQuery($query);
$result = $db->execute();
}
switch ($flagmod) {
case 1:
$db = JFactory::getDbo();
$query = $db->getQuery(true);
$query->select ('id,idadhsymp,adhesionactive,alertefinadhesion,nbjoursavtecheance,imagealertefinadhesion,datefindernadhesion');
$query->from('table_adhcont2');
$db->setQuery($query);
$rows = $db->loadObjectList();
$i=0;
$db = JFactory::getDbo();
foreach( $rows as $row )
{
++$i;
$this_user_id = $row->id;
$this_user_idadhsymp = $row->idadhsymp;
$this_user_adhesionactive = $row->adhesionactive;
$this_user_alertefinadhesion = $row->alertefinadhesion;
$this_user_nbjoursavtecheance = $row->nbjoursavtecheance;
$this_user_imagealertefinadhesion = $row->imagealertefinadhesion;
$this_user_datefindernadhesion = $row->datefindernadhesion;
switch($this_user_idadhsymp) {
case 1:
switch($this_user_adhesionactive) {
case 1:
$this_user_nbjoursavtecheancenew = 'NA';
$this_user_imagealertefinadhesionnew = '/images/Icones/AdhesionActive/button-blue.png';
$this_user_alertefinadhesionnew = 1;
$this_user_adhesionactivenew = 1;
break;
case 2:
$nowDate = strtotime($this_user_datefindernadhesion);
$thenDate = strtotime(date("Y-m-d"));
$dateDiff = - ($thenDate - $nowDate);
$this_user_nbjoursavtecheancenew = round($dateDiff / 86400);
if ($this_user_nbjoursavtecheancenew < 0) {
if ($this_user_nbjoursavtecheancenew > -45) {
$this_user_adhesionactivenew = 4;
$this_user_alertefinadhesionnew = 4;
$this_user_imagealertefinadhesionnew = '/images/Icones/AdhesionActive/button-red.png';
}
else {
$this_user_adhesionactivenew = 1;
$this_user_alertefinadhesionnew = 1;
$this_user_imagealertefinadhesionnew = '/images/Icones/AdhesionActive/button-blue.png';
}
}
else {
$this_user_adhesionactivenew = 2;
$this_user_alertefinadhesionnew = 2;
$this_user_imagealertefinadhesionnew = '/images/Icones/AdhesionActive/button-orange.png';
}
break;
case 3:
$nowDate = strtotime($this_user_datefindernadhesion);
$thenDate = strtotime(date("Y-m-d"));
$dateDiff = - ($thenDate - $nowDate);
$this_user_nbjoursavtecheancenew = round($dateDiff / 86400);
if ($this_user_nbjoursavtecheancenew < 0) {
if ($this_user_nbjoursavtecheancenew > -45) {
$this_user_adhesionactivenew = 4;
$this_user_alertefinadhesionnew = 4;
$this_user_imagealertefinadhesionnew = '/images/Icones/AdhesionActive/button-red.png';
}
else {
$this_user_adhesionactivenew = 1;
$this_user_alertefinadhesionnew = 1;
$this_user_imagealertefinadhesionnew = '/images/Icones/AdhesionActive/button-blue.png';
}
}
else {
$this_user_adhesionactivenew = 3;
$this_user_alertefinadhesionew = 3;
$this_user_imagealertefinadhesionnew = '/images/Icones/AdhesionActive/button-green.png';
}
break;
case 4:
$nowDate = strtotime($this_user_datefindernadhesion);
$thenDate = strtotime(date("Y-m-d"));
$dateDiff = - ($thenDate - $nowDate);
$this_user_nbjoursavtecheancenew = round($dateDiff / 86400);
if ($this_user_nbjoursavtecheancenew < 0) {
if ($this_user_nbjoursavtecheancenew > -45) {
$this_user_adhesionactivenew = 4;
$this_user_alertefinadhesionnew = 4;
$this_user_imagealertefinadhesionnew = '/images/Icones/AdhesionActive/button-red.png';
}
else {
$this_user_adhesionactivenew = 1;
$this_user_alertefinadhesionnew = 1;
$this_user_imagealertefinadhesionnew = '/images/Icones/AdhesionActive/button-blue.png';
}
}
else {
$this_user_adhesionactivenew = 4;
$this_user_alertefinadhesionnew = 4;
$this_user_imagealertefinadhesionnew = '/images/Icones/AdhesionActive/button-red.png';
}
break;
}
break;
default:
$this_user_nbjoursavtecheancenew = '---';
$this_user_imagealertefinadhesionnew = '/images/Icones/AdhesionActive/button-violet.png';
$this_user_adhesionactivenew = 0;
$this_user_alertefinadhesionnew = 0;
break;
}
$IDinput = '{rowid}';
$query = $db->getQuery(true);
// Fields to update.
$fields = array(
$db->quoteName('nbjoursavtecheance') . ' = ' . $db->quote($this_user_nbjoursavtecheancenew),
$db->quoteName('imagealertefinadhesion') . ' = ' . $db->quote($this_user_imagealertefinadhesionnew),
$db->quoteName('adhesionactive') . ' = ' . $db->quote($this_user_adhesionactivenew),
$db->quoteName('alertefinadhesion') . ' = ' . $db->quote($this_user_alertefinadhesionnew),
);
$this_user_id = $i;
$conditions = array(
$db->quoteName('id') . ' = '. $db->quote($this_user_id)
);
$query->update($db->quoteName('table_adhcont2'))->set($fields)->where($conditions);
$db->setQuery($query);
$result = $db->execute();
}
break;
default:
break;
}
I can create an array but i don't know write the query correctly and run this query in cron php script. But i would like it runs automatically every day at 01h00 am.
Perhaps with a temporary table with new values of col of my table and after make an update from ......
It doesn't work with planification cron. Error 500 http
Can you help me ?
Thank you again
Nicolas
Last edited: