cancer10 Posted May 6, 2007 Share Posted May 6, 2007 ok, see the code below <? $rsQry = mysql_query ("select * from tblCustomer"); $arrQry = mysql_fetch_row($rsQry); ?> Now if I try to fetch a Customer's Name from the "Customer_Name" column from the "tblCustomer" table with the following code then I dont get anything: <? echo $arrQry["Customer_Name"]; ?> Why? PS: I have tried this way and it works: <? echo $arrQry[0]; ?> But I want to use the column name instead of the column number. Any idea? Thanx Quote Link to comment https://forums.phpfreaks.com/topic/50228-php-column-names-in-array/ Share on other sites More sharing options...
Barand Posted May 6, 2007 Share Posted May 6, 2007 use $arrQry = mysql_fetch_assoc($rsQry); PS or you can use mysql_fetch_array() in which case both $arrQry[0] and $arrQry['Custome_Name'] both work Quote Link to comment https://forums.phpfreaks.com/topic/50228-php-column-names-in-array/#findComment-246552 Share on other sites More sharing options...
cancer10 Posted May 6, 2007 Author Share Posted May 6, 2007 use $arrQry = mysql_fetch_assoc($rsQry); PS or you can use mysql_fetch_array() in which case both $arrQry[0] and $arrQry['Custome_Name'] both work Now that is a quick and effective reply Thanx a ton mate you solved my problem 2 Quick questiona - 1) does using mysql_fetch_array() will take more resource compared to mysql_fetch_row()? 2) Is this the only difference between mysql_fetch_array() and mysql_fetch_row()? Thanx again Quote Link to comment https://forums.phpfreaks.com/topic/50228-php-column-names-in-array/#findComment-246557 Share on other sites More sharing options...
Barand Posted May 6, 2007 Share Posted May 6, 2007 1 ) mysql_fetch_row() is fastest - returns an indexed array 2 ) mysql_fetch_assoc() returns associative array, keys are the column names 3 ) mysql_fetch_array() by default returns an array with numeric and colnames as indexes (ie each value is returned twice. (you can supply an option second argument to return numeric or associative or both. If you try each of the options followed by echo '<pre>', print_r($arrQry, true), '</pre>'; you will see the diffences Quote Link to comment https://forums.phpfreaks.com/topic/50228-php-column-names-in-array/#findComment-246561 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.