Jump to content


MySQL Question


9 replies to this topic

#1 Robbie.Knox

    Young Padawan

  • Members
  • Pip
  • 42 posts

Posted 25 May 2007 - 07:53 AM

Ok I'm a bit of a beginner when it comes to MySQL. I'm trying to create a table with fields, so obviously I have to declare the lengths of the Varchar fields. If i set it to 20, and I tried inputting a name that's 24 characters long, what would happen?

Thanks

#2 Mr. Matt

    Moderator

  • P2L Staff
  • PipPipPipPip
  • 1,945 posts
  • Gender:Not Telling

Posted 25 May 2007 - 08:30 AM

it would just cut the end of it off i beleive.

#3 Robbie.Knox

    Young Padawan

  • Members
  • Pip
  • 42 posts

Posted 25 May 2007 - 10:33 AM

So if I was for example doing a script, where people type their name into a text box and press submit, and it enters into a database, how would I stop it cutting any off? Would I use Text as the field type? Or limit the characters entered into the text field.

Cheers

#4 Av-

    I Feel Left Out

  • Members
  • PipPipPipPip
  • 1,971 posts
  • Gender:Male
  • Location:10 ft. below sea level

Posted 25 May 2007 - 12:28 PM

Just make sure you make your field large enough. I believe the max length for a varchar field is 255 characters. There's no reason for anybody to have a username longer than 255 chars, so you should be good :biggrin:

#5 Robbie.Knox

    Young Padawan

  • Members
  • Pip
  • 42 posts

Posted 25 May 2007 - 12:30 PM

Ok but if I stuck it to 255, wouldn't that waste space in the database?

Sorry I'm just new to this.

#6 rc69

    PHP Master PD

  • P2L Staff
  • PipPipPipPip
  • 3,827 posts
  • Gender:Male
  • Location:Here
  • Interests:Web Development

Posted 25 May 2007 - 01:18 PM

If we were dealing with C, i could give you a definate answer to that. But since we are not i can only say that, theoretically, yes, it will waste space.

Thats why you have to choose. What is the max length a user name should have. 50 characters maybe? If so, then make a note of that next to the input field (possibly even add the maxlength attribute so they can't enter a name longer than the field).

#7 Robbie.Knox

    Young Padawan

  • Members
  • Pip
  • 42 posts

Posted 25 May 2007 - 03:32 PM

Alright thanks. I was just wandering what scripts such as IPB and vBuletin do to handle this.

#8 WkD

    Young Padawan

  • Members
  • Pip
  • 16 posts
  • Gender:Male
  • Location:Scotland

Posted 25 May 2007 - 03:43 PM

It shouldnt waste any space should it ?? your only setting the max number of characters you can enter so you should only take up the space needed to store the input should you not.

if im wrong sorry :P

#9 Robbie.Knox

    Young Padawan

  • Members
  • Pip
  • 42 posts

Posted 25 May 2007 - 03:47 PM

I thought it wouldn't but apparently if you set it to hold 20 characters, and the data entered is only 10, the other 10 characters will still be stored as blanks, which could affect big websites.

Thanks for all the replies by the way.

#10 joe

    Young Padawan

  • Members
  • Pip
  • 115 posts
  • Location:stuck in the middle of cyber space

Posted 25 May 2007 - 11:26 PM

View PostRobbie.Knox, on May 26 2007, 03:47 AM, said:

I thought it wouldn't but apparently if you set it to hold 20 characters, and the data entered is only 10, the other 10 characters will still be stored as blanks, which could affect big websites.

Thanks for all the replies by the way.

but it depends on the variable type in table which you want to use. For example, for username, i prefer to choose variable type : varchar than char on MySQL.
but, i think it depends to the programmer... :P

joe





1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users