Jump to content

question about arrays


matt.k

Recommended Posts

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 192.168.1.1.

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!!!
Link to comment
Share on other sites

Arrays in PHP are dynamic.

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

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

Ken
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.