I'm not an experienced coder, so please, understand that while I have researched this error I cannot find an example which fits this code insofar as I understand it. I'm getting the string offset error in the subject line from the following snippet of code:
46 $result = mysql_query("SELECT username, pass, reply, authdate FROM somedatabase WHERE username = '$user' ORDER BY authdate DESC LIMIT 5");
47 if($result == false) {
48 echo mysql_error();
}
49 var_dump($result);
50 echo "Number of Rows: " . mysql_num_rows($result). "\n";
51 while ($row = mysql_fetch_array($result)){
52 $data[] = $row;
53 foreach ($data as $col){
54 echo $col['username']['pass']['reply']['authdate'];
55 }
56 echo '<br>';
57 }
This is the output from the command line:
resource(6) of type (mysql result) Number of Rows: 5
PHP Fatal error: Cannot use string offset as an array in /usr/lib/tadpole/CL-wifiacct-full-info.php on line 54
When I declare $result
as an array (using the code $result[]
) in line 46, I get:
PHP Warning: mysql_num_rows() expects parameter 1 to be resource, array given in /pathtofile-blah.php on line 50 Number of Rows:
PHP Warning: mysql_fetch_array() expects parameter 1 to be resource, array given in /pathtofile-blah/.php on line 51