Loading elements into an array dynamically

From: Date: Fri, 12 Oct 2001 14:01:46 +0000
Subject: Loading elements into an array dynamically
Groups: php.general 
Request: Send a blank email to php-general+get-70926@lists.php.net to get a copy of this message
I would be most grateful if someone could tell me where I am going wrong with this. What I am trying to do is to load a list of variables ($surfull) into an array ($surlist) where I will later sort them alphabetically. The mysql_query() works fine as does the mysql_num_rows(). I can print out a list of names in the $surfull form if I uncomment the 'echo $surful;' line - but I can't add those repeated surfulls to my array. ---------------------- $sql = "SELECT hsurn, hforn FROM house WHERE hclass like '$class'"; print "<h1>$class Form List</h1>"; $result = mysql_query( $sql ); $num_rows = mysql_num_rows( $result ); $surlist = array( ); while ( $a_row = mysql_fetch_array($result) ) { $surname = $a_row[hsurn]; $firstname = $a_row[hforn]; $surfull = $surname."=".$firstname; #$surlist = array( $surfull ); $surlist = array_push( $surlist, $surfull ); #echo $surfull; } print $surlist[0]; print "<p><I>Number in class: $num_rows</I><p>\n"; ------------- What I am expecting to happen in the while section is for another element to be added to the array $surlist on each pass through the rows of the query result by the array_push() function. What I get instead is this warning... Warning: First argument to array_push() needs to be an array in /var/www/info/formlist/formlist.php on line 36 ...printed out $num_rows times which suggests that my $surlist = array(); line isn't creating an array as I hoped it would. I'm afraid my own searching through manuals and archives over the last few days hasn't got me anywhere and so I'd be grateful for any advice people might be able to give me. Thanks, Nigel -- Nigel Pauli - I.T. Manager St. John's School, Northwood, U.K. http://www.st-johns.org.uk/

« previous php.general (#70926) next »