Undefined variable?

From: Date: Wed, 28 Apr 2004 15:09:33 +0000
Subject: Undefined variable?
Groups: php.general 
Request: Send a blank email to php-general+get-184886@lists.php.net to get a copy of this message
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? alex hogan ****************************************************************** 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 (#184886) next »