Welcome to WebmasterWorld Guest from 184.108.40.206
Forum Moderators: open
I've been working on a script that will create an SQL statement for dynamic reports, and have hit a bit of a snag. To keep it simple, the basic premise is that I pull all of the available columns and their data types from the database, list them as selectable options, and then add some fields to narrow down selections based on data types.
For example, let's say that my DB has 3 fields that hold boolean data (true/false... actually 1/0). Their datatype represents that fact, so for each of them I add a row of fields to my form that allows the user to select true or false. Each row is dynamic, the number of boolean datatypes will change depending on the DB I'm reporting on. True or false is in a dropdown, and looks like this:
Return Records Where:
something is true
something_else is false
the_last_thing is true
At the end of each row I have a button that allows the user to add that qualifier to their query.
It's generated in php like this:
foreach($boolarray as $thiscolumn)
echo '<tr><td>'.$thiscolumn[name].' is </td><td><select name="bools['.$c.']">';
echo '<option value="1">True</option>';
echo '<option value="0">False</option>';
echo '<input type="hidden" name="boolfield['.$c.']" value="'.$thiscolumn[name].'" />';
echo '<td><input type="button" name="booler" value="Add Qualifier" onClick="addQualifier('.$c.')"></tr>';
Here's a little bit of what I have in my addQualifier().
(the whole thing is pretty big and handles most of the form)
where = where + " " + document.myform.boolfield[boolnum].value
+ " = " + document.myform.bools[boolnum].value;
document.myform.whereclause.value = where; // Populates the textarea
Obviously this isn't working... I get a document.myform.boolfield[boolnum] has no properties, so I'm guessing that's not the way to reference a dynamically built form.
I suppose I *could* use element[i] for this, but it seems awful cumbersome.
<input name="blah" ..>
Is referenced like this, because the  is illegal using "dot" notation
If there is more than one such named element, then a collection is returned, so:
It looks like you are putting something inside the brackets in the input's name. I don't understand the purpose behind that. Is it a PHP thing?
I didn't realize I could have a collection of form items and reference them that way through elements. That should work.
Kinda solves the whole problem if I can do it that way. I'll just get rid of the brackets and $c variable entirely. Thanks. :)