Skip to content

Commit

Permalink
loops may not be the best option
Browse files Browse the repository at this point in the history
sometimes for loops / foreach may be too much
  • Loading branch information
bbannon authored Mar 3, 2024
1 parent 224a5ae commit dc7b70b
Showing 1 changed file with 5 additions and 16 deletions.
21 changes: 5 additions & 16 deletions edit_report_handler.php
Original file line number Diff line number Diff line change
Expand Up @@ -150,24 +150,13 @@
$names[] = 'cal_report_id';
$values[] = $newid;

$sql = 'INSERT INTO webcal_report ( ';
$sql_v = '';

$namecnt = count ( $names );
for ( $i = 0; $i < $namecnt; $i++ ) {
$sql .= ( $i > 0 ? ', ' : '' ) . $names[$i];
$sql_v .= ( $i > 0 ? ', ' : '' ) . '?';
}
$sql .= ' ) VALUES ( ' . $sql_v . ' )';
$sql = 'INSERT INTO webcal_report ( ' . implode ( ',', $names )
. ' ) VALUES ( ?' . str_repeat ( ',?', count ( $names ) - 1 ) . ' )';
$report_id = $newid;
} else {
$sql = 'UPDATE webcal_report SET ';
$namecnt = count ( $names );
for ( $i = 0; $i < $namecnt; $i++ ) {
$sql .= ( $i > 0 ? ', ' : '' ) . "$names[$i] = ?";
}
$sql .= ' WHERE cal_report_id = ?';
$values[] = $report_id; // Push the $report_id to $values.
$sql = 'UPDATE webcal_report SET ' . implode ( ' = ?,', $names )
. ' = ? WHERE cal_report_id = ?';
$values[] = $report_id;
}
}

Expand Down

0 comments on commit dc7b70b

Please sign in to comment.