1

I pull two IDs from a database via a query. One is the table's unique primary key (temp_id), and one is not (auto_id). The query gives me 1,477 records.

When I add these to an array like so, and then var_dump() the array, I get the full 1,477:

<input type="checkbox" name="temp_id[]" value="<?=$auto_id?>">

However when I use this code, suddenly the array only contains 1,001:

<input type="checkbox" name="temp_id[<?=$temp_id?>]" value="<?=$auto_id?>">

Is there any inherent reason for this? As far as I can tell, because $temp_id is unique, this should not cause any "clashes" in the data, or overwritten keys.

FORM CODE:

<?php
if (!isset($_GET['date']) || !filter_var($_GET['date'], FILTER_VALIDATE_INT)) {
    header("Location: ./");
    exit();
}
$date = $_GET['date'];
$upload_date = gmdate("Y-m-d H:i:s", $date);
require_once("db.php");

$automatch_query = mysql_query("SELECT temp_id, auto_id FROM advertisers INNER JOIN update_tempdata ON advertisers.advertiser_id = update_tempdata.auto_id WHERE auto_id > 0 AND upload_date = '$upload_date' ORDER BY advertiser_name");
?>
<form action="match-auto-script.php" method="post">
    <?php
    while ($automatch_data = mysql_fetch_assoc($automatch_query)) {
        extract($automatch_data);
        ?>
        <input class="toggleable" type="checkbox" name="temp_id[<?=$temp_id?>]" value="<?=$auto_id?>" checked>
        <?php
    }
    ?>
</form>

SCRIPT:

<pre><?php var_dump($_POST); ?></pre>
mpdc
  • 3,550
  • 5
  • 25
  • 48
  • Can you share your full code please? – glend Jul 24 '15 at 14:31
  • I can try, but it's a big script. Let me edit the useful parts in to the code. – mpdc Jul 24 '15 at 14:32
  • 1
    Are you sure `$temp_id` is unique? Try to do `array_unique()` and see if you still have 1,477 elements in array. – Alexander Guz Jul 24 '15 at 14:37
  • Maybe the browser only allows 1,001 form elements? Whereas the first example is the same element but as an array so its only 1 element with 1,477 entries. – SamV Jul 24 '15 at 14:41
  • Do you have something like suhosin installed? It might limit your array sizes. – N.B. Jul 24 '15 at 14:41
  • 100% all unique. No Suhosin. Have set `ini_set("max_input_vars", "10000");` on both the form page, and the script page. No luck. – mpdc Jul 24 '15 at 14:48
  • This can happen if your `update_tempdata` contains multiple records for the same `auto_id`. What does `SELECT COUNT(*) FROM advertisers` tell you? – DCoder Jul 24 '15 at 15:06
  • Yes, there are multiple `temp_id`s with the same `auto_id`. Is there any way around this? I thought if the keys were unique... – mpdc Jul 24 '15 at 15:09
  • However if this is the case, would I not get 1,001 records with a sequential integer key, too? – mpdc Jul 24 '15 at 15:21
  • Your problem has nothing to do with sequential/non-sequential keys. It's all due to the way you're naming your input elements. See [1](http://stackoverflow.com/q/4997252/1233508), [2](http://stackoverflow.com/q/8109074/1233508) for more info. – DCoder Jul 24 '15 at 15:31

1 Answers1

0

With thanks to @DCoder's links to answers in other threads, I use the following solution:

<input type="checkbox" name="temp_id[][<?=$temp_id?>]" value="<?=$auto_id?>" checked>

This gives me all 1,477 records as their own array, but at least I have crucial links between each unique temp_id and non-unique auto_id.

Community
  • 1
  • 1
mpdc
  • 3,550
  • 5
  • 25
  • 48