[eluser]John_Betong[/eluser]
[quote author="Jbeasley6651" date="1248062151"]i also get this error
A PHP Error was encountered
Severity: Notice
Message: Array to string conversion
Filename: database/DB_active_rec.php
Line Number: 586[/quote]
I would be tempted to look at the help files and see what return values type you expect to be returned.
When debugging I found that I was continually repeating code to establish the return value type and also the contents. Eventually I wrote the following function and my debugging is now easier. It works on boolean, numerics, string, arrays and Objects.
The function is now in an include file and is the first line to be included in my index,php file.
Code:
// usage:
// fred(&variable;_of_any_type, 'Optional name or details');
//==========================================================================
function fred($data=array('Nothing passed'), $data_name='_missing_$data_name', $data_type='')
{
// $data objects do not display as an array so...
if (is_object($data))
{
$data = get_object_vars($data); // returns with $data = array();
}
// maybe find the $data type
if (empty($data))
{
$data_type = "empty()";
}else{
switch($data)
{
case ('' == $data) :
$data_type = "empty()";
break;
case is_array($data) :
$data_count = count($data);
$data_type = "array($data_count)";
break;
case is_bool($data) :
$data_type = 'boolean';
$data = $data ? 'TRUE' : 'FALSE';
break;
case is_numeric($data) :
$data_type = 'numeric';
break;
case is_object($data) :
$data_type = 'object';
$data = get_object_vars($my_class);
break;
case is_resource($data) :
$data_type = 'resource';
$data_count = mysql_num_rows($data);
$tmp = array();
while ($row = mysql_fetch_assoc($data))
{
$tmp[] = $row;
}
$data = $tmp;
break;
case is_string($data) :
$data_type = 'string';
$data_count = strlen($data);
break;
default:
$data_type = 'oddball';
$data_value = $data;
}//end switch
}//endif
// $data must now be an array or a string, numeric???
$style = 'width:90%; margin:1em; overflow:auto;text-align:left; font-family:Courier; font-size:0.86em; background:#efe none; color:#000; text-align:left';
echo "<div style='$style'>";
echo '<fieldset>';
echo '<legend>John’s Data Determiner asdfasdfsadfsadfasfd</legend>';
echo '<br /><b>Name ==> </b>' .$data_name;
echo '<br /><b>Type ==> </b>' .$data_type;
if (isset($data_count))
{
echo '<br /><b>Count ==> </b>' .$data_count;
}
echo '<br /><b>Value ==> </b>';
echo "<pre style='width:99.98%; margin:-1.2em 0 1em 9.0em'>";
print_r($data);
echo '</pre>';
echo '</fieldset>';
echo '</div>';
return ''; // prevent displaying a 1 return value
}//endfunc
Here is a typical result:
Code:
John’s Data Determiner _missing_$data_name
Name ==> $this->cache_album_list
Type ==> array(16)
Count ==> 16
Value ==>
Array
(
[0] => JohnJokes-style1.jpg
[1] => JohnJokes-style2.jpg
[2] => JohnJokes1.jpg
[3] => JohnJokes2.jpg
[4] => JohnJokes3.jpg
[5] => JohnJokes4.jpg
[6] => Resume 2007 english.htm
[7] => Thumbs.db
[8] => dir_001.bat
[9] => image001.jpg
[10] => image002.jpg
[11] => index.html
[12] => index.php
[13] => johns-jokes.jpg
[14] => kill.txt
[15] => zips
)
18