Re: Building array ?

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Paul Nowosielski wrote:
HI All,

I'm trying to build an array of user id's. This is the code I've written
that does not work.

while($row=mysql_fetch_array($result)){

thereisnothingwrongwithwhitespaceitcanhelplegebilityofyourcode:-)

   // put user ID's into an array;
   $uidToAdmin .= array ("$row[user_id]");

you are concatenating an array (which will be cast to a string) to a string - this won't do what you want. also putting '$row[user_id]' in double quotes is pointless, remember that if you don't put it in double quotes then you have to quote the array 'key' like so (or suffer an E_NOTICE):

<? echo $row['user_id']; ?>

so to build up an (indexed) array (as opposed to associative):

<?php

$uidToAdmin = array();
while ($row = mysql_fetch_array($result)) {
	// put user ID's into an array;
	$uidToAdmin[] = $row['user_id'];
}

// DEBUG:
// I'll assume you will run this via your browser
// therefore a <pre> tag is used to make the output
// readable
echo '<pre>';
var_dump( $uidToAdmin );
echo '</pre>';

?>

I would suggest you take (another?) look at the
documentation on arrays, php arrays are really very very
cool - knowing how to use them properly is a
powerful weapon in your php arsenal. :-)

have fun


   // for debugging
   echo "<br>UID $row[user_id]<BR>";
   echo "<BR>AUID $uidToAdmin[0]";
}

So how can I continue adding to this array in the while loop?

TIA









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


[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux