p2p.wrox.com Forums

Need to download code?

View our list of code downloads.


  Return to Index  

beginning_php thread: creating a multimentional hash.. i think i need $$ here....


Message #1 by "Dan Ostrowski" <dan@t...> on Thu, 2 May 2002 02:35:07
function grabTableInfo($table) {
	global $PHP_SELF;
	global $default_db, $db_user, $db_pass;

	/* first off connect to the db */

	db_connect();

	/* now we need to use the table name to get the field names and 
other info. we just go through, ask myslq to show us the field info, and 
then if the index is non-numerical, we populate an array we then take that 
array and stick it into another array, and return it. */

	$query = "SHOW FIELDS FROM $table";
	$result = @mysql_query($query);
	while($row = mysql_fetch_array($result)){
	  $name = $row['Field'];
	  reset($row);
	  while(list($index, $contents) = each($row)){
		if(!eregi("^[0-9]+$", $index)) {
			$$name[$index] =  $contents;
		}
	  }
	$array[] = $$name;
	}

}


what I am trying to do here is go through and grab all the info for each 
field, and then make that an associative array (hash) and then throw THAT 
into a larger array.

needless to say it's not working very well... heh

the eregi is there because weirdly enough, 2 indexes usually show up.. an 
associative array and then another one with a number and the content 
value. weird, but the eregi works around it.

thoughts?

thanks,
dan

  Return to Index