Jump to content

Recommended Posts

ok, last one - ya'll have been very helpful to me, thanks...

 

i've been given a form configuration to do the backend on, and one of the options is to select from a range of numbers, or from multiple ranges of numbers, i.e.

 

checkboxes:

1 - 200

201 - 500

501 - 1000

1001 - 2000...

 

the values in the database field "enrollment" would be something like 158 or 854 or 1510; i need the search to find ALL the records where 'enrollment' is between 501-1000, etc, and i have no idea how to even configure the checkbox values OR do the query.

 

i can do simple arrays, but this one's over my head.

 

can someone lend a hand? suggest an easy way to do this search?

 

Thanks,

GN

 

 

use the BETWEEN operator in MySQL

 

for every checkbox that's checked just concatenate your SQL statement with

$sql .= "enrollment BETWEEN 1 and 200";

$sql .= "enrollment BETWEEN 201 and 500";

$sql .= "enrollment BETWEEN 501 and 1000";

$sql .= "enrollment BETWEEN 1001 and 2000";

 

 

here's how i'd like to fit the array into what i have for all the other arrays i have:

 

an example (eight others like this):

$offering = $_POST['highest_deg'];
if ($offering != '') {
$offerings = implode(',',$offering);
} else {
if ($offering == '') {
$offerings = '';
}
}
if ($offerings != '') {
$where[] = "offering IN ($offerings)";
} 

select * from table WHERE $where...

 

so i'm trying something like:

 

$enrollment = $_POST['enrollment'];
if ($enrollment != '') {
$enrollment = implode(',',$enrollment);
} else {
if ($enrollment == '') {
$enrollment = "";
}
}

if ($enrollment != '') {
$where[] = "enrollment BETWEEN $enrollment";
} 

 

but i can't see how to configure this array - the others just need an IN operator for 01,02... i made the checkbox values

 

1 and 200

201 and 500

501 and 1000...

but that didn't quite work out with more than one selection...



                      <tr>
                        <td width="20" align="left" valign="middle"><input type="checkbox" name="enrollment[]" value="1 and 200"
                         <?php echo in_array('1 and 200', $_POST['enrollment']) ? ' checked="checked"' : ''; ?> />
                        </td>
                        <td align="left" valign="middle">1 - 200 </td>
                      </tr>
                      <tr>
                        <td width="20" align="left" valign="middle"><input type="checkbox" name="enrollment[]" value="201 and 500"
                        <?php echo in_array('201 and 500', $_POST['enrollment']) ? ' checked="checked"' : ''; ?> />
                        </td>
                        <td align="left" valign="middle">201 - 500 </td>
                      </tr>



i've tried

 

enrollment BETWEEN $enrollment

 

returns

 

enrollment BETWEEN 201 and 500, 501 and 1000;

 

with errors - is there a reason i can't use strings like with an IN operator? problem with spaces ...?

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.