Welcome Guest, Not a member yet? Register   Sign In
A PHP Error was encountered [Help]
#1

[eluser]kikz4life[/eluser]
i have here a standard php script and trying to convert it using CI active record but this error occured to me. The "mysql_fetch_array" said that supplied argument is not a valid MySQL result resource. Tried to substitute it with $data->result_array() coz mysql_fetch_array is equivalent to result_array(so i thoughtSmile).

Code:
$sql='select count('.$postConfig['id'].') as numRows from '.$crudTableName;
                $result = mysql_query($sql);
                $row = mysql_fetch_array($result,MYSQL_NUM);
                $count = $row[0];
                $intLimit = $postConfig['limit'];
        
                if( $count > 0 && $intLimit > 0) { $total_pages = ceil($count/$intLimit); }
                else { $total_pages = 1; }
                $intPage = $postConfig['page'];
                if ($intPage > $total_pages){$intPage=$total_pages;}
                $intStart = (($intPage-1) * $intLimit);
                $sql = 'select '.implode(',',$crudColumns).' from '.$crudTableName;
                if($postConfig['search'] == 'true'){
                    $sql .= ' WHERE ' . $postConfig['searchField'] . ' ' . fnSearchCondition($_POST['searchOper'], $postConfig['searchStr']);
                }
                $sql .= ' ORDER BY ' . $postConfig['sortColumn'] . ' ' . $postConfig['sortOrder'];
                $sql .= ' LIMIT '.$intStart.','.$intLimit;
                
                $result = mysql_query( $sql );
                $data->page = $intPage;
                $data->total = $total_pages;
                $data->records = $count;
                $i=0;
                while($row = mysql_fetch_array($result,MYSQL_NUM)) {
                    $data->rows[$i]['id']=$row[0];
                    $data->rows[$i][$crudConfig['row']]=$row;
                    $i++;
                }

this is the error logs in my firebug
Code:
<h4>A PHP Error was encountered</h4>

<p>Severity: Warning</p>
<p>Message:  mysql_fetch_array(): supplied argument is not a valid MySQL result resource</p>
<p>Filename: controllers/sec_role.php</p>
<p>Line Number: 219</p>

</div>{"page":"1","total":2,"records":"11"}<br />
<b>Fatal error</b>:  ob_start() [&lt;a href='ref.outcontrol'&gt;ref.outcontrol&lt;/a&gt;]: Cannot use output buffering in output buffering display handlers in <b>C:\xampp\htdocs\myweb\system\libraries\Exceptions.php</b> on line <b>162</b><br />

any comments to this? any pointers will be a great help for me.

thanks
#2

[eluser]BrianDHall[/eluser]
Well, first what line is causing the error? That means anything below that line is irrelevant to your error, so that would narrow down the problem.

The PHP error means that the query did not execute successfully, so something is going wrong there. You might check your MySQL log to see if something is going wrong with the query, because that's the problem - mysql_query is not returning a valid 'result resource', which in a case like that usually means it's returned boolean FALSE. You'll want to echo out the SQL you are using on the query and examine it to see if it is in error in some way.

Calling var_dump() on $sql and $result may help to shed light on things for you.
#3

[eluser]kikz4life[/eluser]
thanks for the reply Brian,

found my error, forgot to add this line to my js file: mtype: 'POST', but now my a new problem arise and this is what i found in my firebug logs. As you can see, i was able to query the the data but im not getting anything in return.

Code:
{"page":"1","total":2,"records":"11","rows":[{"id":"1","cell":
{"role_id":"1","role_code":"ADMIN","role_desc":"admin"}},{"id":"2","cell":
{"role_id":"2","role_code":"CEO","role_desc":"CEO"}},{"id":"3","cell":
{"role_id":"3","role_code":"DIVMANAGER","role_desc":"Division Manager"}},{"id":"4","cell":
{"role_id":"4","role_code":"FINANCE","role_desc":"Finance"}},{"id":"5","cell":
{"role_id":"5","role_code":"PROJMANAGE","role_desc":"Project Manager"}},{"id":"6","cell":
{"role_id":"6","role_code":"SALESLADY","role_desc":"Sales Associate"}},{"id":"7","cell":
{"role_id":"7","role_code":"SALESMAN","role_desc":"Sales Manager"}},{"id":"8","cell":
{"role_id":"8","role_code":"leirons","role_desc":"Super User"}},{"id":"14","cell":
{"role_id":"14","role_code":"JC","role_desc":"Junior Consultant"}},{"id":"15","cell":
{"role_id":"15","role_code":"SDSDFSF","role_desc":"SFSDFSDF"}}]}<br />

<b>Fatal error</b>:  ob_start() [&lt;a href='ref.outcontrol'&gt;ref.outcontrol&
lt;/a&gt;]: Cannot use output buffering in output buffering display handlers in
<b>C:\xampp\htdocs\myweb\system\libraries\Exceptions.php</b> on line <b>162</b><br />

i trace it in this library and its this line:
ob_start();

but i doubt this is the real problem here.
#4

[eluser]Ben Edmunds[/eluser]
You will still want to follow the troubleshooting steps Brian posted to narrow this down.

You might also want to re-write your query using the CodeIgniter DB class...




Theme © iAndrew 2016 - Forum software by © MyBB