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 )

 

 

 

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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!

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.