tivrfoa Posted June 10, 2009 Share Posted June 10, 2009 Hi folks! This don't work: $column = mysql_fetch_row($stmt)[0]; I have to do this: $row = mysql_fetch_row($stmt); $column = $row[0]; :-\ Is there a way to do it in a less verbose way? I think that the php guys should implement this in a new release. I'm using 5.2.5. Quote Link to comment https://forums.phpfreaks.com/topic/161675-solved-column-mysql_fetch_rowstmt0-why-not/ Share on other sites More sharing options...
Maq Posted June 10, 2009 Share Posted June 10, 2009 mysql_fetch_row returns an array, it isn't one. I think that the php guys should implement this in a new release. I'm using 5.2.5. Implement what? Not sure what else there is to discuss here. Quote Link to comment https://forums.phpfreaks.com/topic/161675-solved-column-mysql_fetch_rowstmt0-why-not/#findComment-853101 Share on other sites More sharing options...
haku Posted June 10, 2009 Share Posted June 10, 2009 $column = mysql_result($stmt, 0, 0); That should do it for you. Quote Link to comment https://forums.phpfreaks.com/topic/161675-solved-column-mysql_fetch_rowstmt0-why-not/#findComment-853106 Share on other sites More sharing options...
tivrfoa Posted June 10, 2009 Author Share Posted June 10, 2009 $column = mysql_result($stmt, 0, 0); That should do it for you. Thank you haku! This is a very handy function! mysql_fetch_row returns an array, it isn't one. That's the problem, $column = mysql_fetch_row($stmt)[0]; should work. Quote Link to comment https://forums.phpfreaks.com/topic/161675-solved-column-mysql_fetch_rowstmt0-why-not/#findComment-853126 Share on other sites More sharing options...
haku Posted June 10, 2009 Share Posted June 10, 2009 You're welcome. That's the problem, $column = mysql_fetch_row($stmt)[0]; should work. No, it shouldn't work at all. mysql_fetch_array() is not an array, it's a function. You can only call an index (ex: [0]) on an array. Functions don't have indexes. So you can't call an index on mysql_fetch_array(), as you are trying to call an index on a function. The function returns an array. That means that the value it spits out is an array. The function itself isn't an array, only the value it produces. So you can call an index on $column, as it contains the value that mysql_fetch_array() gave it, but you cannot call an index on the function itself. Quote Link to comment https://forums.phpfreaks.com/topic/161675-solved-column-mysql_fetch_rowstmt0-why-not/#findComment-853144 Share on other sites More sharing options...
tivrfoa Posted June 10, 2009 Author Share Posted June 10, 2009 you did'nt understand. here is a Java example. public class MyArray { public static String[] returnArray() { String[] newArray = {"Hello", "World"}; return newArray; } public static void main(String[] args) { System.out.println(returnArray()[0]); // prints Hello. NO PROBLEM!!! } } Quote Link to comment https://forums.phpfreaks.com/topic/161675-solved-column-mysql_fetch_rowstmt0-why-not/#findComment-853184 Share on other sites More sharing options...
Maq Posted June 10, 2009 Share Posted June 10, 2009 PHP is not Java. Quote Link to comment https://forums.phpfreaks.com/topic/161675-solved-column-mysql_fetch_rowstmt0-why-not/#findComment-853197 Share on other sites More sharing options...
tivrfoa Posted June 10, 2009 Author Share Posted June 10, 2009 PHP is not Java. Really ... I didn't know that. Thats why I said that it will be good if this was implemented. Quote Link to comment https://forums.phpfreaks.com/topic/161675-solved-column-mysql_fetch_rowstmt0-why-not/#findComment-853200 Share on other sites More sharing options...
Daniel0 Posted June 10, 2009 Share Posted June 10, 2009 It's planned for PHP6. Quote Link to comment https://forums.phpfreaks.com/topic/161675-solved-column-mysql_fetch_rowstmt0-why-not/#findComment-853205 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.