[thelist] SQL Indexes

Steve Cook sck at biljettpoolen.se
Mon Oct 16 02:53:34 CDT 2000


Mmmmm - indexes!!! (Indexii??)

Well, thanks to everyone for the excellent set of introductions to this
concept. Now, I just need to be sure I've gotten one thing straight. I
create an index within the database using whichever DB admin tools i have
(in my case MySQL, so I'll be writing them into table design). After I've
created them, I simply run my queries as normal, so it's gonna be
	select colA, colB from table;
rather than
	select indexA, indexB from table;
right?

Also I noticed that Adam stressed the importance of "Learn(ing) how to tune
your queries and database designs". Any words on that Adam?

(I can't believe I don't know this stuff - I've only been creating database
backed sites for the last 3 years!).

Just in case this has strayed off-topic - though I don't think so
personally.
<tip type="PHP Switches">

Instead of using a long series of 
	if ($blah==1) {
		// Do something
	} elseif ($blah==2) {
		// Do something else
	} elseif ($blah==3) {
		// Do something
	} else {
		// default choice

.... you get the picture.

You should consider using a switch statement. Some programmers may be
familiar with the 
	select = $blah
		case "1"
			'Do something
		case "2"
			'Do something else
		case else
			'Default choice
	end select
syntax from VBScript and other languages. Well, switch is very similar and
has a feature that makes it more useful in some circumstances.
(The official documentation is here: 
http://www.php.net/manual/control-structures.switch.php )

Basically the syntax is 
	switch ($blah) {
		case "1":
			// Do something
			break;
		case "2":
			// Do something
			break;
		case "3":
			// Do something
			break;
		default:
			// Default choice
	}

The break statements are required at the end of each case, unless you want
to "fall though" to the next pice of code, which allows for the possibility
of grouped cases like this...

	switch ($blah] {
		case "1":
			//Fall through
		case "2":
			// Do some code if the case is either 1 or 2
			break;
		case "3":
			// Do some code if the case is 3
		default:
			// Default choice
	}

See! This is a better way of writing long alternatives than a range of
if..elseif statements.
		

</tip>

.steve


----------------------------------
   WapWarp - http://wapwarp.com
 Wap-Dev - http://www.wap-dev.net
 Cookstour - http://cookstour.org
----------------------------------




More information about the thelist mailing list