how do I fetch and combine data from MySQL then insert into array in PHP -


this question quite specific needs, hence can't find best way this.

what fetch name , surname table people , combine both array end such results:

"bob jones","tony wright",.. etc.

i'm using pdo this. here have:

$attrs = array(pdo::attr_persistent => true);  // connect pdo $pdo = new pdo("mysql:host=localhost;dbname=new", "root", "root", $attrs);  // following tells pdo want throw exceptions every error. // far more useful default mode of throwing php errors $pdo->setattribute(pdo::attr_errmode, pdo::errmode_exception);  $conn = $pdo->prepare("select name, surname people");  $conn->execute(); $results = $conn->fetchall();  foreach($results $row){      $fullname = $row['name'] . "," . $row['surname'];      print_r($fullname); }  

i have tried few things, i'm stuck code @ minute. help, or suggestions appreciated.

$arr = array(); foreach($results $row) {    $arr[] = "{$row['name']},{$row['surname']}"; } echo implode($arr); 

Comments

Popular posts from this blog

Django REST Framework perform_create: You cannot call `.save()` after accessing `serializer.data` -

Why does Go error when trying to marshal this JSON? -