Re: [PHP] a generic getsql() function

2003-06-25 Thread Don Read

On 25-Jun-2003 Thomas Hochstetter wrote:
> Hi guys,
>  
> I wrote a generic getsql() function for my project's class. However, I
> only manage to retrieve a single row. What it should really do is:
> Read all rows into the array (with multiple results).
> The code is below:
>  
> function getsql($sql,$conn,$dbase,&$arr)
> {
> if($conn)
> {
> mysql_select_db($dbase,$conn);
> $result = mysql_query($sql,$conn);
> 
> while ($arr = mysql_fetch_assoc($result))
> {
> return $arr;
> // Something has to happen here!!!

  Nothing will happen here!!!
  You've already returned from the function.

> }


Regards,
-- 
Don Read [EMAIL PROTECTED]
-- It's always darkest before the dawn. So if you are going to 
   steal the neighbor's newspaper, that's the time to do it.

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



RE: [PHP] a generic getsql() function

2003-06-25 Thread French, Alastair
Thomas Hochstetter wrote:
> Hi guys,
> 
> I wrote a generic getsql() function for my project's class. However, I
> only manage to retrieve a single row. What it should really do is:
> Read all rows into the array (with multiple results). The code is
> below: 
> 
> function getsql($sql,$conn,$dbase,&$arr)
> {
> if($conn)
> {
> mysql_select_db($dbase,$conn);
> $result = mysql_query($sql,$conn);
> 
> while ($arr = mysql_fetch_assoc($result))
> { return $arr;
> // Something has to happen here!!!
> }
> }

I think your problem is that you are returning after the first row has been
read, what you need to do is add the row ($arr) to another array using
$new_array[] = $arr or similar. and then move the return $arr to after the
while loop, but then return $new_array not $arr.

Hope this makes sense.

Alastair


==
IMPORTANT NOTICE

The information contained in this e-mail is confidential. It may also
be legally privileged. It is intended only for the stated
addressee(s) and access to it by any other person is unauthorised. If
you are not an addressee, you must not disclose, copy, circulate or
in any other way use or rely on the information contained in this
e-mail. Such unauthorised use may be unlawful.

If you have received this e-mail in error, please inform
Racal Instruments Ltd. immediately by emailing
[EMAIL PROTECTED] or phoning +44 (0)1628 604455 (ask
for the I.T. Dept.) and delete it and all copies from your system.

www.racalinstruments.com

==


-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



[PHP] a generic getsql() function

2003-06-25 Thread Thomas Hochstetter
Hi guys,
 
I wrote a generic getsql() function for my project's class. However, I
only manage to retrieve a single row. What it should really do is:
Read all rows into the array (with multiple results).
The code is below:
 
function getsql($sql,$conn,$dbase,&$arr)
{
if($conn)
{
mysql_select_db($dbase,$conn);
$result = mysql_query($sql,$conn);

while ($arr = mysql_fetch_assoc($result))
{
return $arr;
// Something has to happen here!!!
}
}
else
{
$arr["Error"] = "No connection";
return $arr;
}   
}
 
Thanks.
 
Thomas