Jump to content

Recommended Posts

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

Link to comment
https://forums.phpfreaks.com/topic/50228-php-column-names-in-array/
Share on other sites

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 :)

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

 

 

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.