You have to call mysql_fetch_array for each record in your result set...

$emp_login_wkgrp_id = array ();
$emp_login_grp_id = array ();
$emp_login_role_id = array ();
$i = 0;
while($employee_2 = mysql_fetch_array($result_2)){
  $emp_login_wkgrp_id[$i] = $employee_2["wkgrp_id"];
  $emp_login_grp_id[$i] = $employee_2["grp_id"];
  $emp_login_role_id[$i] = $employee_2["role_id"];
  $i++;
}

mysql_fetch_array will return false when you run out of results, breaking
the while loop.

Check the manual for more info:
http://www.php.net/manual/en/function.mysql-fetch-array.php


mh.


On Mon, 18 Mar 2002, Mullin, Reginald wrote:

> Hi Guys,
>
> I've been experiencing some problems when trying to build 3 arrays with the
> ID values of all of the groups a user belongs to.  (I then want to register
> these arrays into the current session).  The arrays only appear to be
> getting the first value (group ID) instead of all of the values the user
> belongs to.  What am I doing wrong here?
>
> My code looks like this:
>
> File: login.php
> # if $employee_1, query db workgroups table to check if $emp_login_id
> belongs to any groups
> $sql_2 = "SELECT * FROM workgroups WHERE emp_id='$emp_login_id'";
> $result_2 = @mysql_query($sql_2) or die (mysql_error());
> $rows = mysql_num_rows($result_2);
> $employee_2 = mysql_fetch_array($result_2);
> # if match, set workgroups login variables in array, then register
> workgroups login variables in session
> if ($employee_2){
>       $emp_login_wkgrp_id = array ();
>       $emp_login_grp_id = array ();
>       $emp_login_role_id = array ();
>       for ($i=0; $i<$rows; $i++){
>               $emp_login_wkgrp_id[$i] = $employee_2["wkgrp_id"];
>               $emp_login_grp_id[$i] = $employee_2["grp_id"];
>               $emp_login_role_id[$i] = $employee_2["role_id"];
>       }
>       session_register('emp_login_wkgrp_id');
>       session_register('emp_login_grp_id');
>       session_register('emp_login_role_id');
> }
>
> O      From Now 'Till Then,
> \->    Reginald Alex Mullin
> /\      212-894-1690
>
>
>
> **********************************************************************
> This email and any files transmitted with it are confidential and
> intended solely for the use of the individual or entity to whom they
> are addressed. If you have received this email in error please notify
> the postmaster at [EMAIL PROTECTED]
>
>
> www.sothebys.com
> **********************************************************************


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

Reply via email to