If statement being ignored in processing script
If statement being ignored in processing script
Twiggit
Posts: 11Questions: 4Answers: 0
Can someone be so kind as to explain why the if statements in the following procession script are being ignored, regardless of what the value of $nid is the table always returns the results in $q->where( 'cif.cif_data.nid', '(22,32,33,81,82,83)', 'IN', false ). I removed some fields to make it fit.
<?php
session_start();
include( "DataTables.php" );
use
DataTables\Editor,
DataTables\Editor\Field,
DataTables\Editor\Format,
DataTables\Editor\Mjoin,
DataTables\Editor\Upload,
DataTables\Editor\Validate;
$on_sms = array( 953, 459, 3071, 1194);
if ($nid = 600 ) {
Editor::inst( $db, 'cif.cif_data', 'cifid' )
->field(
Field::inst( 'cif.cif_data.cifid' ),
Field::inst( 'cif.cif_data.nid' ),
Field::inst( 'cif.cif_data.uid' ),
Field::inst( 'cif.cif_data.formdate' )
->getFormatter( 'Format::date_sql_to_format', Format::DATE_ISO_8601 )
->setFormatter( 'Format::date_format_to_sql', Format::DATE_ISO_8601 ),
Field::inst( 'cif.cif_data.date_updated' )
->getFormatter( function ( $val ) {
if ( $val != "0000-00-00 00:00:00" ) {
$date = date_create_from_format( 'Y-m-d H:i:s', $val );
return date_format( $date, 'Y-m-d' );
} else {
return "0000-00-00";
}
} )
->setFormatter( 'Format::date_format_to_sql', Format::DATE_ISO_8601 ),
Field::inst( 'crm.primary_profile.fName' ),
Field::inst( 'crm.primary_profile.lName' ),
Field::inst( 'crm.primary_profile.kppFirst' ),
Field::inst( 'crm.primary_profile.kppLast' ),
Field::inst( 'crm.primary_profile.email' ),
Field::inst( 'crm.primary_profile.city' ),
Field::inst( 'crm.primary_profile.pCode' ),
Field::inst( 'crm.primary_profile.province' ),
Field::inst( 'crm.primary_profile.country' ),
Field::inst( 'cif.cif_data.schoolboarddivision' ),
Field::inst( 'cif.cif_data.fullschoolname' ),
Field::inst( 'cif.cif_data.schoolstreetnumber' ),
Field::inst( 'cif.cif_data.schoolstreetname' ),
Field::inst( 'cif.cif_data.schoolunitsuitenumber' ),
Field::inst( 'cif.cif_data.schoolcity' ),
)
->leftJoin( 'crm.primary_profile', 'crm.primary_profile.uid', '=', 'cif.cif_data.uid' )
->leftJoin( 'cif.dropped_program_data', 'cif.dropped_program_data.cifid' , '=' , 'cif.cif_data.cifid' )
->where( function ( $q ) {
$q->where( 'cif.cif_data.nid', '(22,32,33,81,82,83)', 'IN', false )
->where('cif.dropped_program_data.dropped_date', null)
->where('cif.cif_data.formdate', '2023-08-01 00:00:00', '>=')
->where('cif.cif_data.formdate', '2024-08-01 00:00:00', '<');
} )
->process($_POST)
->json();
}
elseif($nid = 39){
if ( in_array( $_SESSION[ 'sm_uid' ], $on_sms ) ) {
Editor::inst( $db, 'cif.cif_data', 'cifid' )
->field(
Field::inst( 'cif.cif_data.cifid' ),
Field::inst( 'cif.cif_data.nid' ),
Field::inst( 'cif.cif_data.uid' ),
Field::inst( 'cif.cif_data.formdate' )
->getFormatter( 'Format::date_sql_to_format', Format::DATE_ISO_8601 )
->setFormatter( 'Format::date_format_to_sql', Format::DATE_ISO_8601 ),
Field::inst( 'cif.cif_data.date_updated' )
->getFormatter( function ( $val ) {
if ( $val != "0000-00-00 00:00:00" ) {
$date = date_create_from_format( 'Y-m-d H:i:s', $val );
return date_format( $date, 'Y-m-d' );
} else {
return "0000-00-00";
}
} )
->setFormatter( 'Format::date_format_to_sql', Format::DATE_ISO_8601 ),
Field::inst( 'crm.primary_profile.fName' ),
Field::inst( 'crm.primary_profile.lName' ),
Field::inst( 'crm.primary_profile.kppFirst' ),
Field::inst( 'crm.primary_profile.kppLast' ),
Field::inst( 'crm.primary_profile.email' ),
Field::inst( 'crm.primary_profile.city' ),
Field::inst( 'crm.primary_profile.pCode' ),
Field::inst( 'crm.primary_profile.province' ),
Field::inst( 'crm.primary_profile.country' ),
Field::inst( 'cif.cif_data.schoolboarddivision' ),
Field::inst( 'cif.cif_data.fullschoolname' ),
Field::inst( 'cif.cif_data.schoolstreetnumber' ),
Field::inst( 'cif.cif_data.schoolstreetname' ),
)
->leftJoin( 'crm.primary_profile', 'crm.primary_profile.uid', '=', 'cif.cif_data.uid' )
->leftJoin( 'crm.on_sm_relationships', 'crm.on_sm_relationships.uid', '=', 'cif.cif_data.uid' )
->leftJoin( 'cif.dropped_program_data', 'cif.dropped_program_data.cifid' , '=' , 'cif.cif_data.cifid' )
->where( function ( $q ) {
$q
->where( 'cif.cif_data.nid', $_SESSION[ 'nid' ], "=" )
->where('cif.dropped_program_data.dropped_date', null)
->where('cif.cif_data.formdate', '2023-08-01 00:00:00', '>=')
->where('cif.cif_data.formdate', '2024-08-01 00:00:00', '<');
} )
->process($_POST)
->json();
} }
This question has an accepted answers - jump to answer
Answers
I don't see where
$nid
is defined? Where is it coming from? Do you mean$_SESSION[ 'nid' ]
?Allan
Hi Allan,
This was part of the problem... there were other rookie mistakes as well. Thank you for the input