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?

Link to comment
Share on other sites

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.