-
looping query?
I have a question. I have a mysql query which runs fine and return the proper records, what I'm trying to do is provide three checkboxes in order to sort be priority (A, B, or C). With the help of rawhide, I found out how to perform a sort if the $priority variable is set. The problem im having is this, since the user can opt to sort by either A, B ect (more than 1), How do I run the sql query for as many times as the $priority Variable is set?
Thanks.
-
Give the fields the same name and values of A, B, and C (or whatever). If more than one checkbox is checked, the values will be returned comma delimited.
Examples:
No checkboxes checked, value of form element = empty
Checkbox A checked only, value of form element = A
Checkbox A and C checked, value of form element = A,C
Then use these values in your query.
-
ok, i did that, I'm noticed that once I select two checkboxes and press go (which submits the form using the method of GET, the URL looks like this.
...?priority=A&priority=B&poc=test+medivas+%281%29
The priority variable isn't comma delimited, and the query seems to only be run on the 2nd priority variable. Do you know why this is?
-
post your new code please.
-
thanks, here's the php...
PHP Code:
if (!isset($priority)) {
$sql="select *, DATE_FORMAT(a_date, '%m/%d/%Y') as a_date_formatted from company, activity where c_id=a_c_id and medivas ='$poc' order by priority asc";
$query=mysql_query($sql);
$numofrows = mysql_num_rows($query);
} else if (isset($priority)) {
$sql="select *, DATE_FORMAT(a_date, '%m/%d/%Y') as a_date_formatted from company, activity where c_id=a_c_id and medivas ='$poc' and priority ='$priority'";
$query=mysql_query($sql) or die(mysql_error());
$numofrows = mysql_num_rows($query);
}
And here are the three checkboxes...
PHP Code:
<form action="" method=GET>
<table BORDER="0" CLASS="priority" ALIGN="CENTER" WIDTH="100%">
<tr><th rowspan=3>Sort by Priority:</Th><th>
A:<INPUT TYPE="Checkbox" NAME="priority" VALUE="A">
</th><th rowspan=3>
<input type=submit value=Go class=btp>
</TH></tr><tr><th>
B:<INPUT TYPE="Checkbox" NAME="priority" VALUE="B">
</Th></TR><tr><th>
C:<INPUT TYPE="Checkbox" NAME="priority" VALUE="C">
</Th></tr></TABLE>
<input type=hidden name=poc VALUE="<?php echo $_GET['poc']; ?>">
</FORM>
You can see the form by making a selection (test medivas (1)) on the combo box on the far right...
http://www.lukesplace.com/Padilla/createreport.php
thanks,thanks,thannks
-
After researching it, it appears that PHP handles it differently than ASP does. Rather than being a comma delimited string, it's returned as an array. So you need to access it as an array.
There's some good info on the subject here: http://us4.php.net/variables.external
-