Sorry for the long delay-- I hope that someone out there might still be with me.
I have put many hours into fiddling with this thing, and now I receive the page number variables when I click 'Save Pages', however the checkDuplicate function isn't picking up on whether or not there are duplicates entered (quick note-- once this part of the code is working, do you think it would be possible to modify it to allow duplicates only if the repeated number is 0?).
Take a gander at my code here (note that the troubled area seems to be the checkDuplicate function at the beginning). The following is the entire page:
<?php
function checkDuplicate( $array ) {
$flag = false;
if ( is_array( $array )) {
$result = array_count_values( $array );
echo " . . . result : ".print_r( $result );
foreach( $result AS $count ) {
if (( int )$count > 2) {
// there is at least 1 duplicate entry
$flag = true;
break;
}
}
}
return $flag;
}
if( $_POST['action'] == 'save' ) {
// Save pages
$article_total = $_POST['article_total'];
$array = array();
for ($j=1; $j<$article_total; $j++) {
$array[$j] = $_POST["page_num_$j"];
echo " __ $j : ".$_POST["page_num_$j"]." __<br> ";
}
//print_r( $array );
$return = checkDuplicate( $array );
if ( $return ) {
echo "<center><strong>Sorry- you have duplicated pages...</strong></center><br><br>";
} else {
echo "<center><strong>All clear!!</strong></center><br><br>";
}
}
// Display page info
$issue_id = $_REQUEST[issue_id];
$query = "SELECT * FROM issues WHERE issue_id = '$issue_id'";
$result = $handle->query( $query );
$issue_info = $handle->fetchAssoc( $result );
$f_publish_date = strftime("%B %Y", $issue_info[publish_date]);
echo "Issue for <b>$f_publish_date</b><br><br>";
echo "<table border=1 cellpadding=7><form name='completeIssue' method='POST' action='$PHP_SELF'>";
$article_query = "SELECT * FROM articles WHERE issue_id = '$issue_id'";
$article_result = $handle->query( $article_query );
$article_index = 1;
if( $article_result ) {
while( $row = $handle->fetchArray( $article_result )) {
echo "<tr><td><b>$row[article_title]</b></td>";
echo "<td><select name=page_num_$article_index>";
$article_index++;
for( $i=0; $i<26; $i++ ) {
if( $i == 0 ) {
echo "<option value='$i'>Not listed</option>";
} else if( $row[page_num] == $i ) {
echo "<option value='$i' selected>$i</option>";
} else {
echo "<option value='$i'>$i</option>";
}
}
echo "</select></td>";
echo "<td><a href='editArticle.php?action=edit&id=$row[article_id]'>Edit</td>";
echo "<td>Remove from this issue</td></tr>";
}
echo "<tr><td> </td>
<input name='action' type='hidden' value='save'>
<input name='article_total' type='hidden' value='$article_index'>
<td><input type=submit value='Save pages'></td>
<td> </td></tr></form></table>";
}
?>
I know it is very newbie-ish of me to include the code from the whole page, but I just can't bring myself to spend any more hours on something that feels like it should be so simple. I greatly appreciate any more help I can get on this.
Thank you,
Ange52