Re: Saving database data into Array!!!

From: Date: Sun, 20 Feb 2000 16:57:15 +0000
Subject: Re: Saving database data into Array!!!
References: 1  Groups: php.dev 
Request: Send a blank email to php-dev+get-15710@lists.php.net to get a copy of this message
Mark Lo wrote: > > Hi everyone, > > I can't get the following code to work. Please tell me what i did wrong > on it. Thank You.. > > Mysql_pconnect("localhost","user_name","password"); > Mysql_select_db("database"); > $query="select first_name, last_name from table; > $result=mysql_query($query); > $numrows=mysql_num_rows($result); > > The problem starts here... > > $x=0; > for ($index=0; $index<$numrows; $index++) > { > $first=mysql_result($result, $index, "table.first_name"); > $first[$x]=$first; your trying to copy $first into itself :-). you might want to replace lines 17-18 with $first[$x]=mysql_result($result, $index, "table.first_name"); or even better - $first[]=mysql_result($result, $index, "table.first_name"); // take a look at http://php.net/manual/html/function.array-push.html about this syntax hope that helps! Tom > $x+=1; > } > When the $x reached the value of 2.... > I got this error message....from the web page... > Warning: Illegal string index in .....on line 18 which is > ($first[$x]=$first;) > > -- > --------------------------------------------------------------------- > Please check > "http://www.mysql.com/Manual_chapter/manual_toc.html" > before > posting. To request this thread, e-mail mysql-thread28388@lists.mysql.com > > To unsubscribe, send a message to: > <mysql-unsubscribe-tom=zworg.com@lists.mysql.com> -- Tom Fishwick e-mail tom@zworg.com | Free web based email web http://zworg.com/ | at http://zworg.com/

« previous php.dev (#15710) next »