Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

change end number of variable

Status
Not open for further replies.

ThomasJSmart

Programmer
Sep 16, 2002
634
hi, im a bit stuck here,

i have a variable called $name

now i need to get a list of $name with a number on the end,
and i need the number to change with every pass,
like this:

Code:
$n=1; 
include '../connect.php';
$result = mysql_query("SELECT * FROM ppl",$db);
while ($myrow = mysql_fetch_array($result))
   {
   $user$n = $myrow[first]; $n=$n+1;
   }
mysql_close();

so i would get a variable list like this

$user1 = name1
$user2 = name2
$user3 = name3
$user4 = name4
$user5 = name5

exept its not working, i think its mostly because of the $user$n bit, but im not sure

how can i solve this?

many thanks,
Thomas Smart
 
hah! iv solved it
i just removed $user from $user$n

DUH!!!!!

:)
 
Why don't you just use an array? This is exactly what arrays are for.
An example:
Code:
$users = array();
$i = 1;
include '../connect.php';
$result = mysql_query("SELECT * FROM ppl",$db);
while ($myrow = mysql_fetch_array($result))
{
    $users[$i] = $myrow[first];
    $i++;
}
mysql_close();
Then $users[1] would contain name1, $users[2] woudl contain name2 etc. //Daniel
 
cool :) this works too,

thnx :)

-i learn sumthin new every day -
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top