Jump to content

[SOLVED] Difference between $row[1] and $row['column_name'] ?


Recommended Posts

I pull rows from the database using

$row = mssql_fetch_row($sql)

where $sql is returned from mssql_query

 

I am trying to figure out why I can use

echo $row[1];

 

but whenever i try to use

echo $row['column_name'];

 

I get errors like "Notice: Undefined index: column_name on row xx"

 

I have seen the second example used many times in sample code so I am trying to figure out what I am doing wrong since it is so much easier to keep track of what I am echoing where.

If you would like to use the field name as key in your array, you should use mssql_fetch_array($sql);

There is an optional parameter, which you could use to return the array with numbered keys, named keys or both (default).

Check http://www.php.net/mssql_fetch_array.

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.