Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

PHP echo returning the word 'Array'

Been lurking on Stackoverflow for a long time but this is my first post. I am receiving a error related to displaying an array which is supposed to be populated by a mysql query. The echo function just returns ArrayArrayArray instead of what is supposed to be there. The mysql query is comparing a form input (the variable $data) .

<?php
$data = $_POST["search"];
global $data;

// Create Connection
$con = mysqli_connect(xxxxx,xxxxxx,xxxxx,xxxxx);

// Check Connection
if (mysqli_errno($con))

{
    echo "Failed To Connect To The Database" ;
}


//Perform Query To Compare And Return Results
$result_array = array();
$query = " SELECT url FROM data WHERE url LIKE '%$data%' "  ;
$result = mysqli_query($con, $query);
// While Loop To Return All Comparable Results
    while ($row = mysqli_fetch_array($result)) {

 $result_array[] = $row['url'];

 echo $result_array ;


}
?>
like image 676
Kirmaan Aboobaker Avatar asked Feb 10 '14 15:02

Kirmaan Aboobaker


2 Answers

echo will print a string, try using something like print_r() or var_dump() instead

Example

echo '<pre>';
print_r($result_array);
echo '</pre>';

<pre> will allow for easier reading of the array

like image 71
Jamie Taylor Avatar answered Sep 29 '22 07:09

Jamie Taylor


You can try with following code.

<?php echo '<pre>'; print_r($result_array); echo '</pre>'; ?>
like image 26
Monirul Islam Avatar answered Sep 29 '22 08:09

Monirul Islam