Basically I use this handy function to processing db rows (close an eye on PDO and/or other stuff)
function fetch($query,$func) {
$query = mysql_query($query);
while($r = mysql_fetch_assoc($query)) {
$func($r);
}
}
With this function I can simply do:
fetch("SELECT title FROM tbl", function($r){
//> $r['title'] contains the title
});
Let's say now I need to concatenate all $r['title']
in a var (this is just an example).
How could I do that? I was thinking something like this, but it's not very elegant:
$result = '';
fetch("SELECT title FROM tbl", function($r){
global $result;
$result .= $r['title'];
});
echo $result;