lynxus Posted December 22, 2009 Share Posted December 22, 2009 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 ) Quote Link to comment Share on other sites More sharing options...
anthylon Posted December 22, 2009 Share Posted December 22, 2009 Try using mysql_fetch_assoc directive instead of mysql_fetch_array. It will return recordset with column names instead of index number. Please, set the topic status [solved] if this works for you! Quote Link to comment Share on other sites More sharing options...
lynxus Posted December 22, 2009 Author Share Posted December 22, 2009 There are no column names. Due to the way it has 30 or 40 left joins etc. it doesn't return a colmn name. ( and it uses MSsql not MySQL ) Quote Link to comment Share on other sites More sharing options...
anthylon Posted December 22, 2009 Share Posted December 22, 2009 Sorry about that! :'( Have you tried with analogy: mssql_fetch_assoc($query) ? It must work! Quote Link to comment Share on other sites More sharing options...
cags Posted December 22, 2009 Share Posted December 22, 2009 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. Quote Link to comment Share on other sites More sharing options...
teynon Posted December 22, 2009 Share Posted December 22, 2009 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. Quote Link to comment Share on other sites More sharing options...
anthylon Posted December 22, 2009 Share Posted December 22, 2009 Hm, even if he is using SELECT * FROM... it still must return name of column. As cags said he should try print_r($row); and see how it looks like. Quote Link to comment Share on other sites More sharing options...
lynxus Posted December 22, 2009 Author Share Posted December 22, 2009 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! Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.