Forum Moderators: coopster

Message Too Old, No Replies

max input vars - How Big is too big?

         

SeanF

1:16 pm on Aug 29, 2020 (gmt 0)

5+ Year Member Top Contributors Of The Month



Hi

I have a table companies in a MySQL database. In a separate table is a list of events and and a third table records if a company is a prospective attendee at a given event. I am creating a (very large) form that would display a large list of companies (rows) and a <select> field for each event (columns) to allow me to see and modify prospect status for each company.

A company search loops through the companies and, for each company, loops through the events and finally checks to see if that company is a prospect for that event. On each company row is a <select> field to allow me to configure those variables. As search might include 3,000 lines.

I am sure huge forms like this are to be avoided but I want a method for occasionally looking at a big list and going line-by-line to view and reset status. Occasionally, that would be more convenient than opening each company record individually. (I deliberately want a huge list)

In any case, I wind up with a huge multidirectional array which might be:
<select name = 'prospect_select[$company_id,$event_id]'>

Therefore the number of variables exceeds the max_input_vars.

Is there a reasonable limit as to how large you set max_input_vars in php.ini?

Aside from this particular page consuming a lot of memory, will setting a high max_input_vars affect the system performance generally?

Is there a better way to do this? (probably)

w3dk

5:01 pm on Aug 29, 2020 (gmt 0)

10+ Year Member Top Contributors Of The Month



...will setting a high max_input_vars affect the system performance generally?


Simply having the value set high wouldn't affect performance at all. It depends on whether you make use of this or not. But AFAIK the reason for this setting is a security one, not a performance one. From the docs: "Use of this directive mitigates the possibility of denial of service attacks which use hash collisions."

You mention "3000 lines" - is that 300 input elements? Whilst the PHP default is 1000, the default on a shared server I use is 8000. So, I assume that is well within "safe limits".

Is there a better way to do this? (probably)


You could use JavaScript to only generate form elements when you interact OR change the data. You could use JS to display the data. You could create a hidden form element that contains the changed data. So, you only submit "changed" data back to the server. That way you are going to be well within the number of max_input vars, assuming you are only changing a handful of vars.

DaveWave

8:00 pm on Aug 31, 2020 (gmt 0)

10+ Year Member



Having one massive form that does this is horrible, don't do it.

So the best solution would be to use javascript and fire on the onchange event of each select element. Suggest you look at learning jQuery which simplifies this. This lets you validate and save your changes as you go along.

If you don't want to do that you might want to consider building a container page that hosts an iframe for each company, each iframe being its own form that would let you update each company as you go along. Again, lets you validate and save as you go along but don't use for a customer environment!

Another hack would be to wrap each company in its own tag and use the target to specify one iframe that you position statically on your page, or perhaps another tab that you could pull out to a different screen.

...but javascript is really the best and most obvious answer.

SeanF

1:02 pm on Sep 5, 2020 (gmt 0)

5+ Year Member Top Contributors Of The Month



Thanks for the reply, DaveWave. I am changing my approach to use an onchange event on the form.

I have what's probably a rookie mistake:

The php script loops through each company and assigns a 'company_id' and for each company, loops through the events and assigns an 'event_id' and there is a <select> field with a 'category' value assigned for each 'company'/'event' pair: cat[$company_id,$event_id]

Then a "prospect" array is assigned:
$prospect_array = array($company_id,$shw_id,$category_id);
$prosp = json_encode($prospect_array);

and the select option is:
<option value= $prosp $selected> $category</option>

Each of these is an 'onchange' event and looks like:
<select name = 'category_select[$company_id,$event_id]' id='cat.$company_id.$event_id' onchange='CategorySelected()'>

Just as a test, the CategorySelected() script currently looks like this:
<script type='text/javascript'>
function CategorySelected(){
alert('Change was made');
var choice = document.getElementById('cat.$company_id.$event_id').value;
alert(choice);
}
</script>

the 'onchange' event is firing successfully but the problem is that the var 'choice' that is displayed by the alert, regardless of which <select> field triggers it is the $prosp value of the very last field in the array. I.e. it is always ["13968","24",""].

I'm sure it's just a syntax error... what am I doing wrong?

Once I get this working correctly, I think I can get JQuery / Ajax to execute the MySQL functions.

Thanks

DaveWave

8:52 am on Sep 9, 2020 (gmt 0)

10+ Year Member



I think if you look at the source of your html when you've loaded your page your function would look like

var choice = ["13968","24",""];

Your php code is running on the server when the page is rendered, the script runs on the client. It looks like you are expecting your php variable array to be read later from your script which is not possible.

I would suggest you use the data attibute to mark your elements (or parents for brevity) with the correct company/event/category then pass in the element to your function.

NickMNS

1:11 pm on Sep 9, 2020 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



@sean F and others.
Your problem above is resolved in the thread you created on that specific problem here:
[webmasterworld.com...]

JAB Creations

2:17 am on Nov 17, 2020 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Sean, stick to using double-quotes on XML/HTML and single quotes for JavaScript. Once you get more advanced you'll greatly appreciate why.

Suggest you look at learning jQuery which simplifies this.


jQuery is one of the absolute worst things that has ever happened to the web. The list of reasons to not use it is longer than the amount of it's bandwidth wasting "code" a single request worth of bandwidth (in the 0.00001% of the time that only one copy is being forced to download).

John