You are here: Re: 1 field or two? « PHP SQL « IT news, forums, messages
Re: 1 field or two?

Posted by Marco Hauer on 06/09/05 00:09

"Nicholas Sherlock" <n_sherlock@hotmail.com> wrote in message
news:d83f85$nc5$1@lust.ihug.co.nz...
> toedipper wrote:
> > I mean, if the countryname fields are unique anyway what is the point of
> > creating an id field? It just seems to me to create extra baggage.
>
> It should be much faster to index on an integer field than a string field.
>
> Cheers,
> Nicholas Sherlock

First it's much faster and I think today we can live with 1 byte for this.
I use it like this:

CREATE TABLE countrys(id TINYINT UNSIGNED, countryname VARCHAR(40));


But more important is that you can do something like this:

<select name='countryid' size='1'>";
$query = "select * from countrys order by countryname";
$result = mysql_query($query,$link);
while ($row = mysql_fetch_array($result, MYSQL_ASSOC)) {
echo"<option value='{$row['id']}'";
if ($countryid == $row['id']) { echo" selected";}
echo">{$row['countryname']}</option>\n"; }
mysql_close($link);
echo"</select>

Like you can see is from every user only the countryid stored in the table.
So this is not only much faster but save also much space. For every user
only 1 byte in place of the countryname!

 

Navigation:

[Reply to this message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация