tags:

views:

51

answers:

3

When I do a print_r, I get a number 1 between the array blocks. I have no idea where it is coming from.

This is causing errors in my log. I can fix this by testing with is_array but I want to know where this is coming from.

I'm making two queries but yet I have a third array in there. What is going on?????

mysqli_result Object
(
    [current_field] => 0
    [field_count] => 2
    [lengths] => 
    [num_rows] => 110
    [type] => 0
)
mysqli_result Object
(
    [current_field] => 0
    [field_count] => 1
    [lengths] => 
    [num_rows] => 12
    [type] => 0
)
1                    <-------------------------------------HERE
mysqli_result Object
(
    [current_field] => 0
    [field_count] => 1
    [lengths] => 
    [num_rows] => 1
    [type] => 0
)

$this->conn->query("CALL phoneIsRegistered($phone,@phone)");

$res = $this->conn->query("SELECT @phone");

    $result = mysqli_query($this->conn, $query) or die('Error: '.mysqli_error($this->conn));

    if($result)
    {
        while($row = $result->fetch_object())
        {
            if($row)
            {
                print_r($row);
            }
        }
        $this->disconnect();
    }

This is what the loop looked like before I began trying to find this.

    $this->connect();
    $result = mysqli_query($this->_conn, $query) or die('Error: '.mysqli_error($this->conn));

    if($result){
        $i=0;
        $res = array();
        while($row = $result->fetch_object()){
            if($row){
                $res[$i++] = $row;
            }
        }
        $this->disconnect();
        return $res;
    }else{
        return false;
    }
A: 

I'll bet you a beer that at some point while adding those mysqli_results to your array, you are pushing a true value into the array, maybe when the variable you work on turns out not to be a valid mysql_result or due to some other misdirected check or comparison.

You would have to show us the complete loop you are using to fill the array.

Pekka
Hi Pekka, you helped me last night. Thanks for lending a hand. Let me grab the complete loop before I started pulling everything apart. brb.
jim
There you go Pekka. I've posted it above
jim
BTW: The true value, if that's what it is, is not inside the array. It's outside the array block which is why it is so disturbing to me.
jim
Really odd, I can't see anything wrong with the code. Can you pinpoint where the `1` comes from by doing random outputs around the code? Is it the result of a single `print_r()` command`? fetch_object() is not supposed to return `1` or `true` in any circumstance.
Pekka
That's what I'm doing now and you know what? I'm not seeing this number value when I do a print_r() inside my db class. So.. when the object is returned, somewhere along the way, it is picking up this value. I'm baffled...
jim
Pekka, I'm getting this error now: Fatal error: Call to a member function fetch_object() on a non-object. What exactly does this mean? This is referring to the same line in the while loop that gathers the results.
jim
I take it this is not important any more, seeing that you are on a different point already in your 2nd question?
Pekka
Generally Call to a member function fetch_object() on a non-objectMeans the SQL returned an error.
MindStalker
A: 

Whenever I am using print_r I see these 1's come up a lot also. I believe that this page would answer your question.

http://stackoverflow.com/questions/720161/number-appears-after-array-stored-in-session

It should not hurt anything....

Metropolis
A: 

Beside using print_r or vardump, you should consider using FirePHP or PHP Quick Profiler to help you debugging and displaying variable's value.

With FirePHP, you can display the value into Firebug's console. Using, PHP Quick Profiler, there will be a console added at the bottom of the page that can be used to display any value that you need.

Donny Kurnia