Jump to content


question about arrays

  • Please log in to reply
1 reply to this topic

#1 matt.k

  • New Members
  • Pip
  • Newbie
  • 1 posts

Posted 09 March 2006 - 08:17 PM

What im trying to do here is pull information from a MySQL database. And put all the data into an array. Basicly. Im pulling the collum names from an external file and i am reading it in the php script. As it reads each line and will grab the data from the collum which is named the same. So. If i opened up XYZ.txt and was reading it. And the first line said Servers. It would goto the Table and pull the info from the 'Servers' collum. I was wondering if this syntax will work. Havent had a change to try it out yet. And wont be able to for a little bit.

$x will be the collum name of the current Table .. and $rs is obviously the data from the record set.

$UserData = Array ($x => $rs)

so if i put in echo $UserData[Servers] .. i would need it to print out the data from that collum in the DB. which would be already stored in that VAR. so output for example would be

Does the array have to be constant? I know some languages you have pre defined. and you are unable to just set it as something throughout the application. like.. in VB .. you have to say UserData(0 to 100). Is this the same case for PHP? or will the above piece of code work? If this code does not work. Does anyone have any suggestions on how to do something similar

Thanks in advance for the help!!!

#2 kenrbnsn

  • Staff Alumni
  • Advanced Member
  • 8,235 posts
  • LocationHillsborough, NJ, USA

Posted 09 March 2006 - 08:37 PM

Arrays in PHP are dynamic.

You can write this:
<?php $UserData = Array ($x => $rs); ?>
<?php $UserData[$x] = $rs; ?>

Read [a href=\"http://www.php.net/array\" target=\"_blank\"]this section[/a] in the fine manual for more information.


0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users