|
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]
|