#native_company# #native_desc#
#native_cta#

DB Variable Dump

By Andy Chute
on January 9, 2002

Version: 1.0

Type: Function

Category: Databases

License: GNU General Public License

Description: Takes the data in a table row and places it into variables of the field names.

eg. $myrow[“Id”] is now $Id

Useful if you have a lot of fields and are using heredoc syntax which doesn’t support array variables

<?php

/****************************************************
*					DB Variable dump				*
*		created by Funktion Design and Media		*
*													*
*	Places a table row's results and places	them in *
*	variables with the DB Field Name.				*
*****************************************************/

	function dump_array($value,$key) {
		global $$key;
		
		$$key = $value;
		return true;
	}
	
	require('dbconnect.php');									// Database Connection
	$result = mysql_query("select * from Whatever_Table");		// Standard Query
	
	if($currow = mysql_fetch_array($result)) {					// If there are results
		
		do {
			array_walk($currow,'dump_array');					// Dumps the current row into variables, $currow["Id"] is now $Id
		} while($currow = mysql_fetch_array($result));
		
	}