0

The program I use takes items out of a database per query.

<?php myquery(array('region'=>'florida','region'=>'florida','region'=>'florida'));?>

I have regions per example (florida, georgia, delaware, etc.).
After the query it return: more items from one state then the other; nothing; or just one (depending on what users are posting).

Now I would only like to show one (if present) from each state.

I was thing something like this: if (in_array('' '') do this...
But do not know if this is the right function and how to use it.

Edited by pritaeas: Moved.

2
Contributors
2
Replies
26
Views
4 Years
Discussion Span
Last Post by mjsmitten
0

I think it would be easier to adjust your query to return what you want. If you show the query you are using now, we can suggest changes to it.

0

Maybe it's possible to walk through the array, every key one time?
now I use <?php osc_query_item(array('region'=>'florida','region'=>'georgia','region'=>'delaware'));?>
after the query gets all values that belong to an item, such as region, in which i am interested.
I need to walk through the value from region and only do one action, then go to the next region, etc.

function osc_query_item($params = null) {
    $mSearch = Search::newInstance();
    if($params==null) {
        $params = array();
    } else if(is_string($params)){
        $keyvalue = explode("=", $params);
        $params = array($keyvalue[0] => $keyvalue[1]);
    }
    foreach($params as $key => $value) {
        switch($key) {
            case 'author':
                $tmp = explode(",", $value);
                foreach($tmp as $t) {
                    $mSearch->fromUser($t);
                }
                break;

            case 'category':
            case 'category_name':
                $tmp = explode(",", $value);
                foreach($tmp as $t) {
                    $mSearch->addCategory($t);
                }
                break;

            case 'country':
            case 'country_name':
                $tmp = explode(",", $value);
                foreach($tmp as $t) {
                    $mSearch->addCountry($t);
                }
                break;

            case 'region':
            case 'region_name':
                $tmp = explode(",", $value);
                foreach($tmp as $t) {
                    $mSearch->addRegion($t);
                }
                break;

            case 'city':
            case 'city_name':
                $tmp = explode(",", $value);
                foreach($tmp as $t) {
                    $mSearch->addCity($t);
                }
                break;

            case 'city_area':
            case 'city_area_name':
                $tmp = explode(",", $value);
                foreach($tmp as $t) {
                    $mSearch->addCityArea($t);
                }

            case 'results_per_page':
                $mSearch->set_rpp($value);
                break;

            case 'page':
                $mSearch->page($value);
                break;

            case 'offset':
                $mSearch->limit($value);
                break;

            default:
                osc_run_hook('custom_query', $key, $value);
                break;
        }
    }
    View::newInstance()->_exportVariableToView("customItems", $mSearch->doSearch());
}

Edited by mjsmitten

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.