CodeIgniter Forums
Quotes in query - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20)
+--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forumdisplay.php?fid=23)
+--- Thread: Quotes in query (/showthread.php?tid=59564)

Pages: 1 2


Quotes in query - El Forum - 10-21-2013

[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');



Quotes in query - El Forum - 10-21-2013

[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);



Quotes in query - El Forum - 10-21-2013

[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.


Quotes in query - El Forum - 10-21-2013

[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?