MyBB Community Forums

Full Version: what the h-e-c-k is this damn KEY
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
ok so im trying to *improve* my sql

and i googled it
i w3school' ed it

and i tizag'ed it

but for the life of me i can't seem to find what this means

 *****KEY ***** fid (fid, visible, sticky),
 KEY dateline (dateline),
  KEY lastpost (lastpost, fid),
  KEY firstpost (firstpost),
  KEY uid (uid),
  PRIMARY KEY (tid)   <---- this 1 i get 

i think this has something to do with indexes but every where i look indexes have the actual word index in the actual sql statement

anyone out there care to share a nugget of wisdom
"key" and "index" are somewhat interchangeable. I think (not sure though) that different implementations of SQL use different names. MySQL uses "KEY".
Quote:The key() function simply returns the key of the array element that's currently being pointed to by the internal pointer. It does not move the pointer in any way. If the internal pointer points beyond the end of the elements list or the array is empty, key() returns NULL.

Example:
<?php
$array = array(
    'fruit1' => 'apple',
    'fruit2' => 'orange',
    'fruit3' => 'grape',
    'fruit4' => 'apple',
    'fruit5' => 'apple');

// this cycle echoes all associative array
// key where value equals "apple"
while ($fruit_name = current($array)) {
    if ($fruit_name == 'apple') {
        echo key($array).'<br />';
    }
    next($array);
}
?>
This will output:
fruit1<br />
fruit4<br />
fruit5<br />

Source: http://php.net/manual/en/function.key.php

Took me 20 seconds to Google...
(2009-11-16, 12:24 AM)Darkmew Wrote: [ -> ]ok so im trying to *improve* my sql
and i googled it

Quote: KEY dateline (dateline),
KEY lastpost (lastpost, fid),
KEY firstpost (firstpost),
KEY uid (uid),
PRIMARY KEY (tid)

(2009-11-16, 06:36 AM)Zomaian Wrote: [ -> ]
Quote:The key() function simply returns the key of the array element that's currently being pointed to by the internal pointer. It does not move the pointer in any way. If the internal pointer points beyond the end of the elements list or the array is empty, key() returns NULL.

Example:
<?php
$array = array(
    'fruit1' => 'apple',
    'fruit2' => 'orange',
    'fruit3' => 'grape',
    'fruit4' => 'apple',
    'fruit5' => 'apple');

// this cycle echoes all associative array
// key where value equals "apple"
while ($fruit_name = current($array)) {
    if ($fruit_name == 'apple') {
        echo key($array).'<br />';
    }
    next($array);
}
?>
This will output:
fruit1<br />
fruit4<br />
fruit5<br />

Source: http://php.net/manual/en/function.key.php

Took me 20 seconds to Google...

thanks for trying to help , but i was trying to execute a sql statement not php code..

i already know about the key() in php Dodgy

on a side not thanks yumi, you have saved me yet again Smile
A KEY is an INDEX which is also UNIQUE.
^ Not the case with MySQL, unique indexes are specified as "UNIQUE KEY".
However, your definition is perhaps more accurate.