RE: [PHP] Undefined variable? [Solution]

From: Date: Wed, 28 Apr 2004 19:40:24 +0000
Subject: RE: [PHP] Undefined variable? [Solution]
Groups: php.general 
Request: Send a blank email to php-general+get-184898@lists.php.net to get a copy of this message
Nevermind I found it. At the beginning of each of the loops I have the following; $row = mssql_fetch_array($result); And in the condition of the loop I'm running the same call; While($row = mssql_fetch_array($result)){ I am not getting the first record in the query. Since the where clause of the query will probably only return one record I'm getting the 'undefined variable' error. I can't believe I had missed that for so long. Pardon the top post... alex hogan On Wed, 2004-04-28 at 16:09, Alex Hogan wrote: > Hi All, > > I'm getting an undefined variable on a return value from a function. > The function is; > function spanky_select($array1, $array2, $where){ > $query = 'SELECT %s FROM %s WHERE %s'; > $query = sprintf($query, implode(', ',$array1), implode(', > ',$array2), $where); > //print $query; > $result = mssql_query($query); > $row = mssql_fetch_array($result); > $j = 0; > while($row = mssql_fetch_array($result)){ > $lname = $row['lastname']; > $fname = $row['firstname']; > $fields = $row['tkt_title']; > $name[$j] = $lname.", ".$fname; > $j++; > } > return ($name); > } > > When I call this from my page I get the error. > $array1[0] = 'firstname'; > $array1[1] = 'lastname'; > $array1[2] = 'tkt_title'; > $array2[0] = 'personnel'; > $array2[1] = 'ticket'; > $where = "lastname = \"smith\""; > > $row = myselect($array1, $array2, $where); > > > However if I change this line; > > $query = 'SELECT %s FROM %s WHERE %s'; > > to this; > > $query = 'SELECT %s FROM %s ORDER BY %s'; > > and the $where var to; > $where = "lastname, firstname"; > > it returns properly. > > Can someone explain this to me? Why is it having trouble when I change > the where var? ****************************************************************** The contents of this e-mail and any files transmitted with it are confidential and intended solely for the use of the individual or entity to whom it is addressed. The views stated herein do not necessarily represent the view of the company. If you are not the intended recipient of this e-mail you may not copy, forward, disclose, or otherwise use it or any part of it in any form whatsoever. If you have received this e-mail in error please e-mail the sender. ******************************************************************

« previous php.general (#184898) next »