Jump to content

accessing a column with forward slash in name?


operafanboy

Recommended Posts

I have a few column names in my MYSQL table that have a forward slah in them, and when I try to access them with php via something like $row['N/O'] it doesn't work. Is it not possible to access a column name like this if it has a '/' or am I doing something wrong?

Cheers
Link to comment
Share on other sites

Try the following:

In your code instead of / use \/ (that is \ then / not the letter v)

if that doesn't work do that for the data in the table instead.

If that doesn't work you could try // in the data in the table. (not the code though) I don't think that // does anything in the data in the table though.
Link to comment
Share on other sites

Ken; operafanboy;

I'm an idiot, I thought that your data had the / in it not the field names.

I try not to use anything other than numbers and letters in mine. To help identify them I use uper and lower case which is bad enough and causes enough errors because I keep forgetting which ones are capps and not.

I'm an idiot, will stay out now :D
Link to comment
Share on other sites

Thanks, the \/ in the code doesn't work. I think I might just change the column names like kenr said though. Is it considered bad practice to use special characters in column names?

BTW does anyone know of any good tutorials about good coding practices/habits with mysql and php?

cheers
Link to comment
Share on other sites

It looks like my earlier reply got lost in the transition to the new box...

Thinking about your problem...

Slashes in the field name shouldn't cause a problem. PHP doesn't have a problem with array indices with slashes and MySQL doesn't have a problem with field names with slashes.

What indications are you getting that the slash in the field name is causing a problem? Errors?

Ken
Link to comment
Share on other sites

[!--quoteo(post=355585:date=Mar 16 2006, 11:53 AM:name=kenrbnsn)--][div class=\'quotetop\']QUOTE(kenrbnsn @ Mar 16 2006, 11:53 AM) [snapback]355585[/snapback][/div][div class=\'quotemain\'][!--quotec--]
It looks like my earlier reply got lost in the transition to the new box...

Thinking about your problem...

Slashes in the field name shouldn't cause a problem. PHP doesn't have a problem with array indices with slashes and MySQL doesn't have a problem with field names with slashes.

What indications are you getting that the slash in the field name is causing a problem? Errors?

Ken
[/quote]

Just that nothing came up on the webpage when it should have. I've got a feeling it's something I did wrong though or forgot to do. Anyway I've changed the names and everything is working well. Thanks for the help :).
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.