Hello:
I have a table which stores three fields generated by checkboxes from a form. I need to create statistical reports based on these fields.
The code for the HTML form which creates the checkboxes (there can be multiple selections; I used an array for my checkboxes: behavior[], current[], prior[]):
<form action="app_admission_pg4.php" method="post">
<tr><td class="a"><input type="checkbox" name="behavior[]" value="Abuse"<?php echo ( isset ( $_SESSION['behavior'] ) && in_array('Abuse', $_SESSION['behavior']) ? ' checked="checked"' : '' ); ?> />Abuse </td>
<td class="a">
<input type=checkbox name=current[] value="Physical"<?php echo ( isset ( $_SESSION['current'] ) && in_array('Physical', $_SESSION['current']) ? ' checked="checked"' : '' ); ?> />Physical
<input type=checkbox name=current[] value="Emotional"<?php echo ( isset ( $_SESSION['current'] ) && in_array('Emotional', $_SESSION['current']) ? ' checked="checked"' : '' ); ?> />Emotional<br>
<input type=checkbox name=current[] value="Sexual"<?php echo ( isset ( $_SESSION['current'] ) && in_array('Sexual', $_SESSION['current']) ? ' checked="checked"' : '' ); ?> />Sexual
<input type=checkbox name=current[] value="Recent"<?php echo ( isset ( $_SESSION['current'] ) && in_array('Recent', $_SESSION['current']) ? ' checked="checked"' : '' ); ?> />Recent<br></td>
<td class="a">
<input type=checkbox name=prior[] value="Physical"<?php echo ( isset ( $_SESSION['prior'] ) && in_array('Physical', $_SESSION['prior']) ? ' checked="checked"' : '' ); ?> />Physical
<input type=checkbox name=prior[] value="Emotional"<?php echo ( isset ( $_SESSION['prior'] ) && in_array('Emotional', $_SESSION['prior']) ? ' checked="checked"' : '' ); ?> />Emotional<br>
<input type=checkbox name=prior[] value="Sexual"<?php echo ( isset ( $_SESSION['prior'] ) && in_array('Sexual', $_SESSION['prior']) ? ' checked="checked"' : '' ); ?> />Sexual
<input type=checkbox name=prior[] value="Recent"<?php echo ( isset ( $_SESSION['prior'] ) && in_array('Recent', $_SESSION['prior']) ? ' checked="checked"' : '' ); ?> />Recent<br></td>
</tr>
<tr><td class="a"><input type="checkbox" name="behavior[]" value="Depression"<?php echo ( isset ( $_SESSION['behavior'] ) && in_array('Depression', $_SESSION['behavior']) ? ' checked="checked"' : '' ); ?> />Depression </td>
<td class="a">
<input type=checkbox name=current[] value="depr_Mild"<?php echo ( isset ( $_SESSION['current'] ) && in_array('depr_Mild', $_SESSION['current']) ? ' checked="checked"' : '' ); ?> />Mild
<input type=checkbox name=current[] value="depr_Mod"<?php echo ( isset ( $_SESSION['current'] ) && in_array('depr_Mod', $_SESSION['current']) ? ' checked="checked"' : '' ); ?> />Mod
<input type=checkbox name=current[] value="depr_Severe"<?php echo ( isset ( $_SESSION['current'] ) && in_array('depr_Severe', $_SESSION['current']) ? ' checked="checked"' : '' ); ?> />Severe<br></td>
<td class="a">
<input type=checkbox name=prior[] value="depr_Mild"<?php echo ( isset ( $_SESSION['prior'] ) && in_array('depr_Mild', $_SESSION['prior']) ? ' checked="checked"' : '' ); ?> />Mild
<input type=checkbox name=prior[] value="depr_Mod"<?php echo ( isset ( $_SESSION['prior'] ) && in_array('depr_Mod', $_SESSION['prior']) ? ' checked="checked"' : '' ); ?> />Mod
<input type=checkbox name=prior[] value="depr_Severe"<?php echo ( isset ( $_SESSION['prior'] ) && in_array('depr_Severe', $_SESSION['prior']) ? ' checked="checked"' : '' ); ?> />Severe<br></td>
</tr>
<tr><td class="a"><input type="checkbox" name="behavior[]" value="Lying"<?php echo ( isset ( $_SESSION['behavior'] ) && in_array('Lying', $_SESSION['behavior']) ? ' checked="checked"' : '' ); ?> />Lying </td>
<td class="a">
<input type=checkbox name=current[] value="lying_Mild"<?php echo ( isset ( $_SESSION['current'] ) && in_array('lying_Mild', $_SESSION['current']) ? ' checked="checked"' : '' ); ?> />Mild
<input type=checkbox name=current[] value="lying_Mod"<?php echo ( isset ( $_SESSION['current'] ) && in_array('lying_Mod', $_SESSION['current']) ? ' checked="checked"' : '' ); ?> />Mod
<input type=checkbox name=current[] value="lying_Severe"<?php echo ( isset ( $_SESSION['current'] ) && in_array('lying_Severe', $_SESSION['current']) ? ' checked="checked"' : '' ); ?> />Severe<br></td>
<td class="a">
<input type=checkbox name=prior[] value="lying_Mild"<?php echo ( isset ( $_SESSION['prior'] ) && in_array('lying_Mild', $_SESSION['prior']) ? ' checked="checked"' : '' ); ?> />Mild
<input type=checkbox name=prior[] value="lying_Mod"<?php echo ( isset ( $_SESSION['prior'] ) && in_array('lying_Mod', $_SESSION['prior']) ? ' checked="checked"' : '' ); ?> />Mod
<input type=checkbox name=prior[] value="lying_Severe"<?php echo ( isset ( $_SESSION['prior'] ) && in_array('lying_Severe', $_SESSION['prior']) ? ' checked="checked"' : '' ); ?> />Severe<br></td>
</tr>
<input type="submit" name="btnSubmit" id="btnSubmit" value="Page 5 >>" class="btn" >
<input type="hidden" name="submitted" value="TRUE" />
</form>
To store the data in the table for all three checkboxes I used the implode function.
$_SESSION['behavior1'] = implode(' , ', $_SESSION['behavior']);
$_SESSION['current1'] = implode(' , ', $_SESSION['current']);
$_SESSION['prior1'] = implode(' , ', $_SESSION['prior']);
I inserted the values into the table with the following SQL statement:
$query7 = "INSERT INTO behavior_check (client_id, behavior, current, prior)
VALUES ($cid, '$_SESSION[behavior1]', '$_SESSION[current1]', '$_SESSION[prior1]')";
$result7 = mysql_query ($query7) or die (mysql_error());
The result of the query produces the following table:
client_id | behavior | current | prior
1 | Abuse, Lying, Depression | Physical, Emotional, Mild, Mild | Emotional, Severe, Severe
2 | Abuse, Depression | Emotional, Sexual, Physical, Severe, Mild | Physical, Severe, Severe
So, I have the table with all the values by client_id. From this table, I need to create statistical reports to show, for example,
- total number of clients by behavior
Abuse = 2
Lying = 1
Depression = 2
In theory, I would need to write SQL statements like:
SELECT COUNT(behavior) from behavior;
Is it possible, when using the implode function to store data, to create statistical reports as I described? If so, how do I go about doing that? Since all the fields in the table are arrays, I don't know how to extract the data in order to query against those fields.
Can someone help me out?
Thank you in advance.