Welcome Guest, Not a member yet? Register   Sign In
Quotes in query
#11

[eluser]Tpojka[/eluser]
[quote author="ivantcholakov" date="1382359911"]This is what you know, I can't tell. Where does the list of zip-codes come from? From the database, from a text file, from a PHP hard-coded array/string? Who makes/updates this list? And in time this situation may change.[/quote]

Exactly.

Btw, I am realizing that $array is processed with some kind of function before passing in query, i.e:

Code:
$zipcodes = $this-input->post['zipcodes'];
do_process($array)
{
  foreach($array as &$elem)
  {
    // make any escaping, checking or needed function
  }
  return $array;
}

$zipcodes = do_process($zipcodes);
SELECT * FROM (`TABLE`) WHERE `Zipcode` IN ('$zipcodes');
#12

[eluser]ivantcholakov[/eluser]
Code:
// Place within a controller's method that should process user input (POST).

    $zipcodes =
        explode(' ',
            trim(
                preg_replace('/\s+/', ' ',
                    preg_replace('/[^0-9]/', ' ', $this-input->post['zipcodes'])
                )
            )
        );

    // var_dump($zipcodes);

    $this->db
        ->select()
        ->from('table')
        ->where_in('zipcode', $zipcodes)
        ->get()
        ->result_array();

    //var_dump($result_array);
#13

[eluser]ZioN[/eluser]
[quote author="Tpojka" date="1382359000"]Can you tell how it looks like your input of zip codes: is that something visitor/user type by self minded?[/quote]
It's not something a visitor types. It's coming from an API. this API utilizes an external database which gets the zipcodes based on the visitors location (globally).

[quote author="ivantcholakov" date="1382359911"]This is what you know, I can't tell. Where does the list of zip-codes come from? From the database, from a text file, from a PHP hard-coded array/string? Who makes/updates this list? And in time this situation may change.

Nevertheless, in all cases I would prefer the query builder, if it is able to do the job. It is a safer approach. And it has additional benefits: cleaner code, abstraction from the database server type.[/quote]
As stated above from an external database. And i'd rather use the codeigniter approach aswel.
#14

[eluser]Tpojka[/eluser]
It is more simplier now, because an API gives consistent values all the time.
If you are getting it just like an array:
Code:
$zipcodes = array('0100', '0110', '3100');
You don't need to bother with apostrophs and commas and spaces. You already have just values in there.
But also, there is a need to save it like varchar column in table because of zeros on first positions in number.
Is that, or better asked, what is the raw format API send you?




Theme © iAndrew 2016 - Forum software by © MyBB