Jump to content


Photo

accessing a column with forward slash in name?


  • Please log in to reply
7 replies to this topic

#1 operafanboy

operafanboy
  • New Members
  • Pip
  • Newbie
  • 5 posts

Posted 16 March 2006 - 03:12 AM

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

#2 Humpty

Humpty
  • Members
  • PipPipPip
  • Advanced Member
  • 132 posts

Posted 16 March 2006 - 03:42 AM

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.
- Humpty
  #> Where does the light go when it goes out?

#3 kenrbnsn

kenrbnsn
  • Staff Alumni
  • Advanced Member
  • 8,235 posts
  • LocationHillsborough, NJ, USA

Posted 16 March 2006 - 03:49 AM

How about changing the name of the column in your database?

Ken

#4 Humpty

Humpty
  • Members
  • PipPipPip
  • Advanced Member
  • 132 posts

Posted 16 March 2006 - 04:16 AM

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
- Humpty
  #> Where does the light go when it goes out?

#5 operafanboy

operafanboy
  • New Members
  • Pip
  • Newbie
  • 5 posts

Posted 16 March 2006 - 04:27 AM

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

#6 Twentyoneth

Twentyoneth
  • Members
  • PipPipPip
  • Advanced Member
  • 118 posts
  • LocationGlasgow, KY

Posted 16 March 2006 - 04:31 AM

what about something like:

[!--quoteo--][div class=\'quotetop\']QUOTE[/div][div class=\'quotemain\'][!--quotec--]$row[N//O][/quote]

$newrow = stripslashes($row);

#7 kenrbnsn

kenrbnsn
  • Staff Alumni
  • Advanced Member
  • 8,235 posts
  • LocationHillsborough, NJ, USA

Posted 16 March 2006 - 04:53 PM

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

#8 operafanboy

operafanboy
  • New Members
  • Pip
  • Newbie
  • 5 posts

Posted 18 March 2006 - 03:50 AM

[!--quoteo(post=355585:date=Mar 16 2006, 11:53 AM:name=kenrbnsn)--][div class=\'quotetop\']QUOTE(kenrbnsn @ Mar 16 2006, 11:53 AM) View Post[/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 :).




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users