note 45506 deleted from function.array by nlopess

From: Date: Thu, 09 Sep 2004 12:50:13 +0000
Subject: note 45506 deleted from function.array by nlopess
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-76319@lists.php.net to get a copy of this message
Note Submitter: paul at hamlington dot co dot uk ---- Don't know if anybody will use this but I created a very simple function that puts the results of your query into a 2d array and passes it back I have put the connection function on there as well so you can see how it all works: /*-- Database Connection --*/ function connection() { /* MySQL Database Connection Remote Server */ $db_connection = mysql_connect("URL", "USERNAME", "PASSWORD") or die("Could not connect to database"); /* Database Selection Remote Database */ mysql_select_db ("DATABASE NAME", $db_connection) or die("Could not find database"); return $db_connection; } /*-- Generic Query Results to array --*/ function rs($query) { /* Excute The Query */ $array = mysql_query ($query, connection()); $lr = mysql_num_rows($array); /* Total Rows */ /* Loop through putting each row into new column in array */ for($rloop=0; $rloop<=$lr-1; $rloop++) { $generic_array[$rloop] = mysql_fetch_row($array); } mysql_close(); return($generic_array); } Simple pass your query to this function $test = rs("SELECT field1 FROM table1"); then just manipulate $test array keeps things alot tidier.

« previous php.notes (#76319) next »