Jump to content

Confusing mysql_fetch_row output problem


OriginalSixRules

Recommended Posts

I am executing the following query.  Please note the first column name:

 

$sqlString="SELECT href, urlParam, urlParamVal, linkText, target FROM menulinks WHERE menu='leftSideMenu' ";

 

$result = mysql_query($sqlString);

 

The following code:

while ($thisRow = mysql_fetch_row($result )){

    echo $thisRow['href'];

}

 

results in this error:

Notice: Undefined index: href in C:\EasyPHP-5.3.2\www\my_app\display\leftSideMenu.php on line 25

 

If I go to output the column names with this code:

echo "The column names are-";

$numRows=mysql_num_rows($result );

$i = 0;

while ($i < mysql_num_fields($result )){

$field = mysql_fetch_field($result , $i);

echo $field->name."<br/>";

$i++;

}

 

The output from the above code is...

The column names are-

href

urlParam

urlParamVal

linkText

target

 

I am obviously selecting the column named 'href,' and the column name can be displayed as selected. 

 

If I change the code in the first loop to use $thisRow[0] I get the output I expect.  In fact, if I use any of the column names instead of numbers I get the "invalid index" error.

 

What simple mistake am I making and/or missing?

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.