Welcome Guest, Not a member yet? Register   Sign In
consult the database
#1

[eluser]gmferreir[/eluser]
hello my friends,

help me I'm lost at this point

$data = $this->input->post('address');
$da = $this->data_base_model->saddress($data);


$da is an array and need to make another appointment in another table but I'm completely lost. I've tried doing a foreach on the model but still did not work.

return of this query have to query tree tables.

sorry for my english, I'm from Brazil
#2

[eluser]duartix[/eluser]
First thing: You need to replace the word appointment by query or no one that doesn't know Portuguese will understand what you need. I mean, it took me quite a while to figure you meant "consulta".

[quote author="gmferreir" date="1383477357"]hello my friends, [/quote]

Code:
$data = $this->input->post('address');
$da = $this->data_base_model->saddress($data);
You haven't loaded your model. You'll need to do it before you execute the function saddress:
Code:
$this->load->model('data_base_model');

[quote author="gmferreir" date="1383477357"]
return of this query have to query tree tables.
[/quote]

If the query spans 3 tables I believe you'll have to write it manually in the model, something like this:

Code:
public function saddress($data) {
        try {
            if (!is_null($data)) {
                // Do the query
                $query =
                        "SELECT *
                            FROM   a, b, c
                         WHERE   a.address LIKE '%" . $data . "%' and
                                         a.id1=b.id1 AND
                                         b.id2=c.id2";
                $result = $this->db->query($query);
            
                if (!empty($result) and $result->num_rows>0)
                    return $result->result_array();
            }
            return NULL;
        } catch (Exception $ex) {            
            // Log de eventuais erros
            error_log("Erro em saddress, $data= " . $data . ") \n" . $ex->getMessage());
            return NULL;
        }
    }

I gave you a bonus: exception handling! Wink
#3

[eluser]gmferreir[/eluser]
duartix,
thank you very much.

actually two bonus, with the English lesson.


Ajudou demais, muito obrigado !!!!!!!!!!!!!

Grande abraço.
#4

[eluser]duartix[/eluser]
Query updated with some ' that was missing near the % sign.
If this solution worked, then mark my answer as "solution" so the post so it won't show as "needs solution" on the forum.
#5

[eluser]gmferreir[/eluser]
very, very good.

thanks.

when you want to come to Brazil so tell me.

rsrs.




Theme © iAndrew 2016 - Forum software by © MyBB