For developer resources , code snippets, examples and tutorials.
| Tech |
Title |
Updated |
|
 | Enter Key to submit or validate, Default Button | 2012-04-01 10:26:17 |
If you have a search page, or any functionality on your site that requies the user to enter something then press the enter key to submit it. You may not want the user to have to click the button. Simply enter the text and press the enter key.
To achieve this use the following code..
<script>
document.body.onkeypress = presskey ;
function presskey(evt)
{
var evt = (evt) ? evt : event
var charCode = (evt.which) ? evt.which : evt.keyCode
if (charCode == 13)
{
callFunction();
}
}
</script>
|
|
 | Search and Find string contained in Linux Files | 2012-04-12 08:27:55 |
To search in the current directory:
grep "needle" /home/myuser/*.txt
To search recursively append the -r option
grep -r "needle" /home/myuser
|
|
 | Linux find file | 2012-04-16 16:12:25 |
To find a file in linux, use
find -name "<filename>"
to do a case insensitive search use
find . -print | grep -i "<filename>"
|
|
 | Wildcard search in MySQL | 2012-04-14 08:41:01 |
If you have a table full of names, and only want to select the records that contain the name JOHN for example. This is how you do that.
SELECT * FROM <tablename> WHERE name = "JOHN"
however if you have someones name that was JOHNNY, then that would not be returned..
To add a Wild card search we do the following.
SELECT * FROM <tablename> WHERE name LIKE "%JOHN%"
This returns every name that has the word JOHN in it.
If you want to search for names with JOHN only at the beginning you would do this.
SELECT * FROM <tablename> WHERE name LIKE "JOHN%"
|
|
 | MYSQL FULL TEXT search | 2012-04-02 12:19:47 |
Step 1.. change the table type to MYISM
ALTER TABE <table> ENGINE = MYISAM
Step 2.. Add FULLTEXT to the fields that you want to search text in.
ALTER TABLE <table> ADD FULLTEXT ( field1 , field2 )
Step 3.. Now do free text searching through your text fields.
SELECT * FROM <table> WHERE MATCH( field1, field2) AGAINST ('search string') |
|
 | Changing the Minimum FULL TEXT search length | 2012-04-02 14:08:28 |
The length of FULL TEXT searching defaults to 4, this is not good if you are looking for text with 3 characters..
To change this you need to update the variable ft_min_word_len
this is readonly, and the server MUST be restarted and the table reindexed after setting.
to set, locate the config file ( my.cnf )
and add the following in the [mysql] area.
[mysqld]
ft_min_word_len=3
the ini on windows is usually located
"%ProgramFiles%\MySQL\MySQL Server 5.1\my.ini"
|
|
 | Searching in a PHP String | 2012-04-03 07:17:52 |
To see if a string exists in a PHP String, we ask for the position of the search text
$pos = strpos($haystack, $needle);
if ($pos === false)
{
// NOT FOUND
}
else
{
// FOUND
}
if the string was found , it returns the location of the string. |
|