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
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.
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
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
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
[!--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 :).

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.