I have a statement that would be really easy to write out (see below) but I can't seem to figure it out for Magento. The statement is:
SELECT * FROM addresses
WHERE
$postcode_from BETWEEN (pc_from AND pc_to)
OR $postcode_to BETWEEN (pc_from AND pc_to)
OR (
$postcode_from <= pc_from
AND $postcode_to >= pc_to
)
Is this going to be possible or am I going to have to write out the statement and manually feed it to Magento?
EDIT*
Here's what I've got currently. It works but is messy:
$select = $read->select()->from($table);
$select->where(
$read->quoteInto(" ( ? >= postcode_from", $upload['postcode_from']) .
$read->quoteInto(" AND ? <= postcode_to )", $upload['postcode_from']) .
$read->quoteInto(" OR ( ? >= postcode_from ", $upload['postcode_to']) .
$read->quoteInto(" AND ? <= postcode_to )", $upload['postcode_to']) .
$read->quoteInto(" OR ( ? <= postcode_from ", $upload['postcode_from']) .
$read->quoteInto(" AND ? >= postcode_to )", $upload['postcode_to'])
);
$selection = $read->fetchAll($select);
EDIT
For anyone confused as to what I am trying to achieve:
I have pc_from_1
and pc_to_1
. these are stored in the database.
I also have pc_from_2
and pc_to_2
. These are from user input.
I want to check if any of the following occurs:
// Where this
pc_from_1 pc_to_1
|-------------------|
pc_from_2 pc_to_2
|--------------|
//or this
pc_from_1 pc_to_1
|-------------------|
pc_from_2 pc_to_2
|--------------------|
// Or this
pc_from_1 pc_to_1
|-------------------|
pc_from_2 pc_to_2
|---------------------------------|
// occurs