Jump to content

How to access database fields as an array variables ?


linux1880

Recommended Posts

Hi friends,

a quick print_r() shows the following array while connecting to my database. How to get them as individual items and display on the website ?

Array
(
    [0] => Array
        (
            [id] => 52
            [document_name] => xyz
            [document_ext] => gif
            [download_file_name] => ktm_impact.gif
            [upload_dt] => 2010-08-11
        )

)

Link to comment
Share on other sites

a quick print_r() shows the following array while connecting to my database

 

Connecting to a database does not retrieve data. You seem to be wrapping your results within another array. Can we see how you are actually creating this array?

Link to comment
Share on other sites

Your still being quite vague so I'll just give you a simple example.

 

foreach ($document as $doc) {
  echo $doc['id'] . '<br />';
  echo $doc['document_name'] . '<br />';
  echo $doc['document_ext'] . '<br />';
  echo $doc['download_file_name'] . '<br />';
  echo $doc['upload_dt'] . '<br />';
}

Link to comment
Share on other sites

Thank you thorpe, that's using foreach, i want to access some fields without using loops, for example if i access

 

 echo $document['document_name'];

directly, it's giving me error.

 

A PHP Error was encountered

Severity: Notice

Message: Undefined index: document_name

Filename: libraries/Loader.php(673) : eval()'d code

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.