FOREACH / Array Help
Posted: Sat Aug 04, 2007 12:10 pm
feyd | Please use
My FOREACH statements look like this:
Can someone help me out?
Thank you.
feyd | Please use
Code: Select all
,Code: Select all
and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read: [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]
Hello:
I was wondering if someone can help me out. I have a form which creates three arrays: behavior[], current[], and prior[].
I need to store the data into two tables: current and prior. I have a third table called behavior which stores the behavior and client_id. All three of these tables will have multiple records per client_id.
The variable behavior is the top level or root array. This variable will store info as Abuse, Fire Setting, Eating Disorder, etc.
The current and prior variables are the child variables.
The current table will have the fields: id, client_id, behavior, current
The prior table will have the fields: id, client_id, behavior, prior
Here is an example of how the data looks in the tables:
The data in the tables should look like this:
behavior table:
id | client_id | behavior
1 | 4 | Abuse
2 | 4 | Agression
current table:
id | client_id | behavior | current
1 | 4 | Abuse | Physical
2 | 4 | Agression | Physical
3 | 4 | Agression | Object
4 | 4 | Agression | Adult
5 | 4 | Agression | Younger Child
prior table:
id | client_id | behavior | prior
1 | 4 | Abuse | Emotional
2 | 4 | Abuse | Verbal
3 | 4 | Agression | Object
4 | 4 | Agression | Adult
5 | 4 | Agression | Younger Child
My problem in coding the form is defining the relationship between "behavior and current" and "behavior and prior". I can't seem to get the arrays created to give me the correct response.
This is the code for my form:Code: Select all
<table class="apptable">
<tr><th scope="col">Behavior</th><th scope="col">Current</th><th scope="col">Past</th></tr>
<tr><td class="i">
<input type="checkbox" name="behavior1[]" value="Abuse"<?php echo ( isset ( $_SESSION['behavior1'] ) && in_array('Abuse', $_SESSION['behavior1']) ? ' checked="checked"' : '' ); ?> />Abuse </td>
<td class="h">
<input type=checkbox name=current1[] value="Physical"<?php echo ( isset ( $_SESSION['current1'] ) && in_array('Physical', $_SESSION['current1']) ? ' checked="checked"' : '' ); ?> />Physical
<input type=checkbox name=current1[] value="Emotional"<?php echo ( isset ( $_SESSION['current1'] ) && in_array('Emotional', $_SESSION['current1']) ? ' checked="checked"' : '' ); ?> />Emotional<br>
<input type=checkbox name=current1[] value="Sexual"<?php echo ( isset ( $_SESSION['current'] ) && in_array('Sexual', $_SESSION['current1']) ? ' checked="checked"' : '' ); ?> />Sexual
<input type=checkbox name=current1[] value="Recent"<?php echo ( isset ( $_SESSION['current1'] ) && in_array('Recent', $_SESSION['current1']) ? ' checked="checked"' : '' ); ?> />Recent<br></td>
<td class="h">
<input type=checkbox name=prior1[] value="Physical"<?php echo ( isset ( $_SESSION['prior1'] ) && in_array('Physical', $_SESSION['prior1']) ? ' checked="checked"' : '' ); ?> />Physical
<input type=checkbox name=prior1[] value="Emotional"<?php echo ( isset ( $_SESSION['prior1'] ) && in_array('Emotional', $_SESSION['prior1']) ? ' checked="checked"' : '' ); ?> />Emotional<br>
<input type=checkbox name=prior1[] value="Sexual"<?php echo ( isset ( $_SESSION['prior1'] ) && in_array('Sexual', $_SESSION['prior1']) ? ' checked="checked"' : '' ); ?> />Sexual
<input type=checkbox name=prior1[] value="Recent"<?php echo ( isset ( $_SESSION['prior1'] ) && in_array('Recent', $_SESSION['prior1']) ? ' checked="checked"' : '' ); ?> />Recent<br></td>
</tr> </table>
<input type="submit" name="btnSubmit" id="btnSubmit" value="Update Record" class="btn" >
<input type="hidden" name="submitted" value="TRUE" />
</form>My FOREACH statements look like this:
Code: Select all
foreach($_POST['behavior1'] as $cvalue)
foreach($_POST['current1'] as $bvalue){
echo "$cvalue:$bvalue<br>";
}Thank you.
feyd | Please use
Code: Select all
,Code: Select all
and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read: [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]