Following 1st script work well and return multiple rows with the data. But when I tried to use this code in a function as shown in the 2nd script I cannot out put data, but it return the number of rows, I tried to use a return array() as shown [here](https://stackoverflow.com/questions/25577678/mysqli-fetch-not-fetching) but still I cannot figure it out to work. Many thanks.

```
<?php
// 1st code
$stmt = $mysqli -> prepare (" SELECT Name, City FROM user_db WHERE id = ? " ) ;
$stmt -> bind_param ('s', $id ) ;
$stmt -> execute () ;
$stmt -> store_result () ;
$stmt -> bind_result ( $name1, $city1  ) ;
while ( $stmt -> fetch () ) { echo $name1 .'-'. $city1  .'<br>' ; }

```

result of 1st code

```
name1-city1
name2-city2
name3-city3

```

2nd code - use 1st code in a function

```
function test ( $mysqli , $id ) {
    $stmt = $mysqli -> prepare (" SELECT Name, City FROM user_db WHERE id = ? " ) ;
    $stmt -> bind_param ('s', $id ) ;
    $stmt -> execute () ;
    $stmt -> store_result () ;
    $stmt -> bind_result ( $name, $city  ) ;
    return $stmt;
}

$stmt = test ( $mysqli , $id );

while ( $data = $stmt -> fetch () ) { 
    echo  $name .'-'. $city  .'<br>' ; 
}

```

result of 2nd code

```
-
-
-

```