jonniejoejonson Posted September 2, 2009 Share Posted September 2, 2009 How do i get the array key values of the following: $sql = "SELECT * FROM posts"; $sql_result = mysql_query($sql,$connection) while ($row = mysql_fetch_array ($sql_result)) { ........ i want the array $row key .......... } kind regards to any responders. Quote Link to comment https://forums.phpfreaks.com/topic/172865-solved-get-the-array-key/ Share on other sites More sharing options...
Mark Baker Posted September 2, 2009 Share Posted September 2, 2009 $sql = "SELECT * FROM posts"; $sql_result = mysql_query($sql,$connection) $key = 0; while ($row = mysql_fetch_array ($sql_result)) { ........ i want the array $row key .......... $key++; } Quote Link to comment https://forums.phpfreaks.com/topic/172865-solved-get-the-array-key/#findComment-911087 Share on other sites More sharing options...
ignace Posted September 2, 2009 Share Posted September 2, 2009 What do you mean by the $row key? $row['columnName'] or $row[0]? Quote Link to comment https://forums.phpfreaks.com/topic/172865-solved-get-the-array-key/#findComment-911088 Share on other sites More sharing options...
mikesta707 Posted September 2, 2009 Share Posted September 2, 2009 array_keys($row) ? Quote Link to comment https://forums.phpfreaks.com/topic/172865-solved-get-the-array-key/#findComment-911090 Share on other sites More sharing options...
TeNDoLLA Posted September 2, 2009 Share Posted September 2, 2009 <?php $sql = "SELECT * FROM some_table LIMIT 1"; $result = mysql_query($sql); $row = mysql_fetch_assoc($result); $keys = array_keys($row); print_r($keys); Quote Link to comment https://forums.phpfreaks.com/topic/172865-solved-get-the-array-key/#findComment-911091 Share on other sites More sharing options...
jonniejoejonson Posted September 2, 2009 Author Share Posted September 2, 2009 thanks one and all, Tendolla has pretty much what im looking for... alternatively: foreach($row as $key => $value){ echo ("<BR>$key : $value");} Quote Link to comment https://forums.phpfreaks.com/topic/172865-solved-get-the-array-key/#findComment-911098 Share on other sites More sharing options...
Mark Baker Posted September 2, 2009 Share Posted September 2, 2009 Oh, so it's the column key rather than the row key Quote Link to comment https://forums.phpfreaks.com/topic/172865-solved-get-the-array-key/#findComment-911231 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.