Jump to content

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


lonewolf217

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.

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.