Click to See Complete Forum and Search --> : Question about recordset
damon2003
10-28-2003, 05:40 PM
I have a query that loops through 3 columns in a database and loops through the values, diplaying them until the end of the recordset.
What I want to do is put each value into its own variable. I know how to put the values into a variable, but it gets overwritten on the next iteration so is it possible to dynamically create new variable names for each record pulled form the database?
any ideas?
Why not use an array?
<?PHP
$ary = array();
for ($i=0; $i<3; $i++) {
$ary[$i] = $i;
}
echo $ary[1]; #echos 1
?>
damon2003
10-28-2003, 06:26 PM
Thanks,
I can use that
actually I just thought that I may not be going about it the right way. What I have is the following displayed on my web page:
field1Value field2aValue checkbox1
field1Value field2aValue checkbox1
and so until the end
I want to only submit values to a script where the user checks the corresponding checkbox. At first I thought about getting individual variables but then I dont know how to manipulate these based on the checkboxs which are also in the loop,
Any suggestions?
thanks
I'd just loop through the checkboxes that have been checked and pull the corresponding values.
damon2003
10-29-2003, 04:56 AM
I dont understand fully.
how would I actually do this?
I'm using PHP, need more detail
would the loop have to go inside the recordset loop. What is used to check if a checkbox is checked or not?
You could try something like this: (note the checkboxes only show up in the $_POST array if they have been checked)
<form action="<?PHP echo $_SERVER['PHP_SELF']; ?>" method="post">
<p><input type="text" name="input_one">
<input type="checkbox" name="check_one"><br>
<input type="text" name="input_two">
<input type="checkbox" name="check_two"><br>
<input type="submit" name="submit" value="Go"></p>
</form>
<?PHP
if (isset($_POST['submit'])) {
$matches = array();
foreach ($_POST as $name => $value) {
if (preg_match("/^check_(\w+)/", $name, $match)) {
$matches[] = "input_".$match[1];
}
}
foreach ($matches as $field) {
echo $_POST[$field]."<br>";
}
}
?>
damon2003
10-29-2003, 08:39 AM
thanks a lot,
this means that I have to dynaically rename every checkbox as checkbox_one, checkbox_2 etc,
how is this done?
damon2003
10-29-2003, 09:42 AM
does this script work? there seems to be a problem with it
It only works if you name things like I did above.