Jump to content

While through SQL query that doesnt have column names.


lynxus

Recommended Posts

Hi Guys,

Ive got a MASSIVE sql query that returns to columns, But doesnt actually have a colum name.

 

Normlaly i could use

while($row = mssql_fetch_array($result))

{

  echo " Layer3Id " . $row["Layer3Id"];

  echo " CustID " . $row["CustomerId"];

}

 

However

in this case i cant use the names..

 

How can i still achieve the same output without column identifiers?

 

IE:

currently it whines that theres undefined indexes ( because the column has no name )

 

 

 

Either use aliases in your SQL query (ie SELECT COUNT(id) AS id_count FROM table).to give the return field a name, alternatively I'd guess it will add them as $row[0], $row[1] etc. but you can use print_r($row) to see what values it contains.

Sounds like your running a query like SELECT * FROM table.

 

If thats the case, the numbers reference the sections in order. Say your table is:

ID

Name

Date

the array would be

0=ID

1=Name

2=Date

 

I don't like using * unless I am using absolutely everything from the table.

Either use aliases in your SQL query (ie SELECT COUNT(id) AS id_count FROM table).to give the return field a name, alternatively I'd guess it will add them as $row[0], $row[1] etc. but you can use print_r($row) to see what values it contains.

 

Good stuff!! I didnt think of that!

 

Thanks!

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.