Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Add a field called "type" that ranks your dropoff and pickup types where lower numbers represent better (more precise) options:</p> <ol> <li>city/city</li> <li>city/country</li> <li>country/city</li> <li>country/country</li> <li>city/region</li> <li>region/city</li> <li>country/region</li> <li>region/country</li> <li>region/region</li> </ol> <p>Since you're storing tables of cities, countries, states, and regions, you can use their ids in your rules table. Modify your rules table to have a schema similar to the following</p> <ul> <li>name</li> <li>type (from above)</li> <li>pickup_type</li> <li>pickup_city_id</li> <li>pickup_state_id</li> <li>pickup_country_id</li> <li>pickup_region_id</li> <li>drop_type</li> <li>drop_city_id</li> <li>drop_state_id</li> <li>drop_country_id</li> <li>drop_region_id</li> </ul> <p>Now, if you know your pickup and destination cities, you should be able to load their state, country, and region ids from your other tables. Then, you can perform the following query:</p> <pre><code> SELECT * FROM rules WHERE ((pickup_type = 'city' &amp;&amp; pickup_city_id = '$pickup_city_id') OR (pickup_type = 'state' &amp;&amp; pickup_state_id = '$pickup_state_id') OR (pickup_type = 'country' &amp;&amp; pickup_country_id = '$pickup_country_id') OR (pickup_type = 'region' &amp;&amp; pickup_region_id = '$pickup_region_id')) AND ((drop_type = 'city' &amp;&amp; drop_city_id = '$drop_city_id') OR (drop_type = 'state' &amp;&amp; drop_state_id = '$drop_state_id') OR (drop_type = 'country' &amp;&amp; drop_country_id = '$drop_country_id') OR (drop_type = 'region' &amp;&amp; drop_region_id = '$drop_region_id')) ORDER BY type ASC </code></pre> <p>That query will look for rules that match your dropoff city, state, country, or region and your pickup city, state, country, or region. Because you're sorting by type, the first result in the set should be the most convenient courier.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload