Welcome Guest, Not a member yet? Register   Sign In
Error Number: 1054?
#1

[eluser]SaSa[/eluser]
why this code have error?
With respect
Code:
search_customer = 1;//$this->input->post('search_customer');
    $where = "id=$search_customer OR name=$search_customer";
    $query = $this->db->get_where('customer', $where);
    if($query->num_rows()==0){
                echo '0';
            }else{
                $data = array();
                foreach ($query->result() as $row)
                {
                   $data[] = $row;
                }
                echo json_encode($data);
            }
error:
Code:
A Database Error Occurred
    Error Number: 1054
    
    Unknown column 'id=1' in 'where clause'
    
    SELECT * FROM (`customer`) WHERE `id=1` OR name=1
    
    Filename: D:\xampp\htdocs\mehdi\system\database\DB_driver.php
    
    Line Number: 330
#2

[eluser]JHackamack[/eluser]
Because Active Record is escaping your id=1 resulting in it thinking you have a column name called 'id=1'.
#3

[eluser]SaSa[/eluser]
Sorry, Not catch!?
please give me a example.
#4

[eluser]JoostV[/eluser]
Code:
$result= $this->db->where('id', $search_customer)
                              ->or_where('name', $search_customer)
                              ->get('customer')
                              ->result_array();
#5

[eluser]SaSa[/eluser]
Code:
$query = $this->db->where('id', $search_customer)->or_where('name', $search_customer)->get('customer');
thanks, but why when that empty is input show all data in database 'customer' ?
i want if input is empty num_row = 0.
#6

[eluser]SaSa[/eluser]
Please help me...
#7

[eluser]JoostV[/eluser]
Hi SaSa, if you are wondering what to do with $result you can do var_dump($result); to see what kind of data it is. And write the rest of the code accordingly.

I'm guessing it would be something like
Code:
$result= $this->db->where('id', $search_customer)
                              ->or_where('name', $search_customer)
                              ->get('customer')
                              ->result_array(); 

If (FALSE == is_array($result) || 0 == count($result) {
    echo 0;
}
else {
    echo json _encode($result);
}
#8

[eluser]JoostV[/eluser]
Or shorter
Code:
echo FALSE == is_array($result) || 0 == count($result) ? 0 : json _encode($result);

Hope I didn't leave in any typos. I hate typing code on an iPad Smile
#9

[eluser]SaSa[/eluser]
Sorry that I misspelled.I do not know much English and it is not my native language.
if input($this->input->post('search_customer')) is empty, output is all data in customer database.
Indeed if input is empty, must output is 0.
now if typed value in input it(where) worked true and output is true.
my problem is here that, why input is empty output is all data in table customer in database?
see you my output when that input is empty: http://www.freeimagehosting.net/newuploads/3f6bd.gif

I am likely the problem is: where
But I do not know how to fix?
What is your comment?

With respect
#10

[eluser]JoostV[/eluser]
I am not quite sure what you mean, but I think it would be something like this:
Code:
// Set customer from post, XSS filtered
$customer = $this->input->post('search_customer', TRUE);

if ($customer == '') {
    // We do not have a customer POST
    echo 0;
}
else {
    // Fetch a customer from the database
    $result= $this->db->where('id', $search_customer)
                              ->or_where('name', $search_customer)
                              ->get('customer')
                              ->result_array();

    echo FALSE == is_array($result) || 0 == count($result) ? 0 : json_encode($result);
}




Theme © iAndrew 2016 - Forum software by © MyBB