note 45506 added to function.array

From: Date: Thu, 09 Sep 2004 12:45:54 +0000
Subject: note 45506 added to function.array
Groups: php.notes 
Request: Send a blank email to php-notes+get-76316@lists.php.net to get a copy of this message
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. ---- Manual Page -- http://www.php.net/manual/en/function.array.php Edit -- http://master.php.net/manage/user-notes.php?action=edit+45506 Delete -- http://master.php.net/manage/user-notes.php?action=delete+45506&report=yes Reject -- http://master.php.net/manage/user-notes.php?action=reject+45506&report=yes Search -- http://master.php.net/manage/user-notes.php

« previous php.notes (#76316) next »