Code Comments
Programming Forum and web based access to our favorite programming groups.On Mon 27 Dec 04, 5:22 PM, S Kumar <ps_php@yahoo.com> said: > Dear group, > I am a novice programmer started doing php to process > a query form of my patients. > > I have a database and one table in it deals with my > patient information. Depending on their condition I > divided their age groups into 3 categories. In my > database a table patient_data has a column age_group > and a patient can be any one of young, middle or old > category. > Now the possibility is that a user can selecct 1 or 2 > or all three options. > > In the query form, I gave the option for a user as a > check box. The piece of html code is as below: > > <DIV>Age group</DIV> > <DIV>Young<input type="checkbox" name="" > value=""></DIV> > <DIV>Middle<input type="checkbox" name="" > value=""></DIV> > <DIV>Old<input type="checkbox" name="" value=""></DIV> > > Problem: > I want to capture the user options and create an SQL > statement: > > Select age_group from patient_data where age_group = > young and old ; > > > I am truly stuck here. Can any one please help me out > to pass this situation. > > Thank you in advance. > > Kumar. It seems as though the SQL itself is pretty straight forward. The where clause would be generated from a conditional based on what values are true. Exactly what are you having difficulty with? Pete PS- How can a single patient be "young", "middle", and "old" at the same tim e? Are you a psychologist? -- The mathematics of physics has become ever more abstract, rather than more complicated. The mind of God appears to be abstract but not complicated. He also appears to like group theory. -- Tony Zee's "Fearful Symmetry" GPG Fingerprint: B9F1 6CF3 47C4 7CD8 D33E 70A9 A3B9 1945 67EA 951D
Post Follow-up to this messageOn Mon 27 Dec 04, 9:22 PM, p <p> said: > > PS- How can a single patient be "young", "middle", and "old" at the same > time? Are you a psychologist? Sorry. There should have been a smiley ":-)" after that sentence. Pete
Post Follow-up to this messageHello Pete:
It is a cancer patients for whom i have data on
preoperative and postoperative procedures and drugs
administered for that condition. my table looks like
this:
S. No Pat_age_group type_of cancer size_of_tumor
1 Old Prostate 5 cm
2 Young breast 3 cm
So, in the case of my table, there is not discrepancy
in age group assignment.
The search page contains a mix of textboxes and
checkboxes.
So, my aim is to allow the user to search
intelligently.
For example: Say there 6 textboxes and 6 checkboxes.
The search terms that can be entered in 1 and 2 boxes
are to be searched in TABLE-A column a_b and a_c. The
search terms that can be entered in 3,4,5 and 6
textboxes are to be searched in TABLE-B columns
b_c,b_d,b_e and b_f.
Now, I have given options to the user in the form of
checkboxes. For example:
Smoking status: Smoker and non-smoker
age group : young, old and middle
And all these options that he checks here are to be
searhed in another table TABLE-C.
Depending on what the user enters the data, I want to
create an SQL statement on the fly and report the
results.
If the user, does not enter text in textboxes 1 and 2
and enters some search term in textbox 3. I want to
capture that term as a variable and create an SQL
statement to search the mother table say TABLE-A.
So I set out to capture all the search terms that the
user enters in the search form as variables. I want to
define some properties to the variables saying if
variable $cancer (Coming from textbox 1) is not null,
then this variable can only be searched in TABLE-A ,
column a_b.
If the user enteres something in textbox 2, then
$tissue (coming from textbox 2) should be searched in
TABLE A, column a_c.
However, in the case of checkboxes, I do not know how
to make variables out of them depensing on what user
selects. Say whatever user cheks in the checkbox,
that variable has to be searched in TABLE-C and
various other columns in that table. I am totally
clueless how I can capture what user checks as a
variable and incorporate into the SQL statement.
I apologise for the lengthy description, being a
person trained on the areas of medicine and biology, I
am unable to communicate what a programmer or a CS
student would do so in order to ask precisely.
So please help me suggesting a easiest way to deal
with a scenario where I can create SQL statements on
the fly easily depending on what user enters in the
search form.
Just for your convenience what exactly I have instead
of imaginary tables that described for exmpleray
purpose.
I appreciate you help a lot and sorry again for
lenghty e-mail that you might have to go through. BTW
I am a mdedical scientist from Baltimore.
Thanks.
K
****************************************
*************
I have a serch page that has both text boxes and check
boxes. The attributes and their tables are written in
the praranthesis. TB - Text box The type of form
element i.e text box or check box is represented in
curly braces.
Cancer {TB} (Table - Experiment; column - experiment
name)
TISSUE {TB} (Table - Sample; Column - Sample name)
Gene Name {TB} (Table - Sequence_annotation ; Column -
fc_gene_symbol)
MOLECULAR FUNCTION {TB} ( Table - Sequence_annotation;
column - fc_molecular_function)
CELLULAR COMPONENT {TB} (Table - sequence_annotation;
column - fc_cellular_component)
BIOLOGICAL PROCESS {TB} (Table - sequence_annotation;
column - fc_biological_process)
AGE GROUP {CHECK BOX}
option 1 : Young (Tabe - patient_data ; column -
patient_age_group)
option 2: Middle (Tabe - patient_data ; column -
patient_age_group)
option 3: Old (Tabe - patient_data ; column -
patient_age_group)
SMOKING {CHECK BOX}
option 1 : No (Tabe - patient_data ; column -
patient_smoking)
option 2 : Yes (Tabe - patient_data ; column -
patient_smoking)
ER {CHECK BOX}
option 1: Positive (Tabe - patient_data ; column -
patient_ER)
option 2: Negative (Tabe - patient_data ; column -
patient_ER)
PR {CHECK BOX}
option 1: Positive (Tabe - patient_data ; column -
patient_PR)
option 2: Negative (Tabe - patient_data ; column -
patient_PR)
RECURRENT STATUS {CHECK BOX}
option 1: < 5 Months (Tabe - patient_data ; column -
patient_recurrent_Status)
option 1: 5-10 moths (Tabe - patient_data ; column -
patient_recurrent_Status)
option 1: > 10 Months (Tabe - patient_data ; column -
patient_recurrent_Status)
METASTATSIS STAGE {CHECK BOX}
Option 1: Yes (Tabe - patient_data ; column -
patient_metastasis_stage)
Option 2: No (Tabe - patient_data ; column -
patient_metastasis_stage)
--- Peter Jay Salzman <p@dirac.org> wrote:
> On Mon 27 Dec 04, 9:22 PM, p <p> said:
> age_group =
> me out
> and "old" at the same
>
> Sorry. There should have been a smiley ":-)" after
> that sentence.
>
> Pete
>
> --
> PHP Database Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>
>
__________________________________
Do you Yahoo!?
The all-new My Yahoo! - Get yours free!
http://my.yahoo.com
Post Follow-up to this messageOn Mon 27 Dec 04, 8:48 PM, S Kumar <ps_php@yahoo.com> said:
> Hello Pete:
>
> However, in the case of checkboxes, I do not know how
> to make variables out of them depensing on what user
> selects. Say whatever user cheks in the checkbox,
> that variable has to be searched in TABLE-C and
> various other columns in that table. I am totally
> clueless how I can capture what user checks as a
> variable and incorporate into the SQL statement.
Hi Kumar,
I've never played with databases before 3 or 4 days ago, and maybe played
around with HTML forms a couple of times in my life. I'm still learning the
basics of SQL, so if you don't know something about SQL, I almost certainly
don't know it!
However, if all you need to know is how to access checkboxes in PHP... that
I've played around with. I wrote a sample program, "check.php".
Sorry for the painfully obvious comments, but I wrote them for me just as
much as for you. :) I tried to write it as defensively as I know how, but
like I said, I'm just learning this stuff myself. Hope it's OK! :)
You should be able to generalize this to more than one "set" of checkboxes,
but if not, let me know and I'll whip up another sample program. Basically,
all the magic is in the "name=" parameter in the <input> tag. Use the same
name for things that related options. Use different names for different
groups of checkboxes (but put them all within the same <form> tag.
Note: I just realized that I used a for loop. I recall reading somewhere
that foreach is more efficient than for, so that may be one way to improve
this. Anyhow, here it is.
HTH,
Pete
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"';
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html>
<head>
<title>Checkboxes With PHP Example</title>
</head>
<body>
<form action="<? echo $_SERVER['PHP_SELF'] ?>?action=posted" method="post">
<input type="checkbox" name="mycheckbox[]" value="<? echo date("l"); ?>"/>Ch
oice 0<br/>
<input type="checkbox" name="mycheckbox[]" value="hello"/>Choice 1<br/>
<input type="checkbox" name="mycheckbox[]" value="2.3827"/>Choice 2<br/>
<p><input type="submit"></p>
</form>
<?
// This checks to see if the "submit" button was hit.
//
if ( ! isset($_REQUEST['action']) )
exit(0);
// The checkbox group with name "foobar[]" can be accessed
// by $_POST['foobar']. As always, $_POST is an array, so
// the thing that we assign $_POST to is also an array, which
// can be counted, indexed, foreach'ed, etc.
//
// If nothing was checked, the $_POST['mycheckbox'] array doesn't
// exist, which will print a warning if we set E_ALL on. So let's
// check to see if it exists first, and if not, tell the user to
// check something.
//
if ( ! isset($_POST['mycheckbox']) )
die("I'm going to sit back and wait until you check something!");
$mycheckbox = $_POST['mycheckbox'];
echo '<ul>';
for ($i=0; $i < count($mycheckbox); $i++)
{
// This shows you how to access checkboxes in PHP. Now that you have a
// list of all the stuff that's been checked, you can use a whole bunch
// of conditional statements to form your complex SQL.
//
echo "<li>mycheckbox[$i]: $mycheckbox[$i]</li>";
}
echo '</ul>';
?>
</body>
</html>
--
The mathematics of physics has become ever more abstract, rather than more
complicated. The mind of God appears to be abstract but not complicated.
He also appears to like group theory. -- Tony Zee's "Fearful Symmetry"
GPG Fingerprint: B9F1 6CF3 47C4 7CD8 D33E 70A9 A3B9 1945 67EA 951D
Post Follow-up to this messagePowered by vBulletin
Copyright 2000-2006 Jelsoft Enterprises Limited.