Re: Saving database data into Array!!!

From: Date: Sun, 20 Feb 2000 16:39:18 +0000
Subject: Re: Saving database data into Array!!!
References: 1  Groups: php.dev 
Request: Send a blank email to php-dev+get-15708@lists.php.net to get a copy of this message
> 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"); $dbh = mysql_pconnect("localhost", "user_name", "password"); > > Mysql_select_db("database"); > $query="select first_name, last_name from table; $query="select first_name, last_name from table"; > > $result=mysql_query($query); $result = mysql_query($query, $dbh); > > $numrows=mysql_num_rows($result); > The problem starts here... Not the best way to loop through your results (not in-correct however), try instead: while ($row = mysql_fetch_object($result)) { $first[] = $row->first_name; } if you want to do it your way here are some corrections > > $x=0; remove this > > for ($index=0; $index<$numrows; $index++) increment $x here for ($index=0, $x=0; $index<$numrows; $index++, $x++) > > { > $first=mysql_result($result, $index, "table.first_name"); > $first[$x]=$first; Change variable name or eliminate intermediary step, ie: $first[$x] = mysql_result($result,$index,"table.first_name"); > > $x+= 1; remove this completely (by the way $x+=1 is the same as $x++) > > > } > 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;) Also this is a development list, for help on debugging/creating PHP scripts see the main list for PHP users (http://www.php.net/support.php3 for more information on how to suscribe). Regards, Sterling Hughes sterling@designmultimedia.com

« previous php.dev (#15708) next »