Skip to content

Commit

Permalink
Merge pull request #469 from bbannon/foreach
Browse files Browse the repository at this point in the history
loops may not be the best option
  • Loading branch information
craigk5n authored Aug 31, 2024
2 parents 88aea1c + 5c094d7 commit 9ef67a2
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 21 deletions.
10 changes: 5 additions & 5 deletions autocomplete_ajax.php
Original file line number Diff line number Diff line change
Expand Up @@ -115,12 +115,12 @@
}

$data = $sug = [];
for ($i = 0; $i < count ($ret); $i++) {
$sug[$i] = $ret[$i]['name'];
}
for ($i = 0; $i < count ($ret); $i++) {
$data[$i] = $ret[$i]['text'];

foreach ( $ret as $i ) {
$sug[] = $i['name'];
$data[] = $i['text'];
}

ajax_send_object('matches', $sug, $sendPlainText);
} else {
ajax_send_error(translate("Error"));
Expand Down
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 9ef67a2

Please sign in to comment.