MySQL find first, last row

SELECT
this,
query,
SUBSTRING_INDEX(GROUP_CONCAT(CAST(rocks AS CHAR) ORDER BY _date), ',', 1 ) as top,
SUBSTRING_INDEX(GROUP_CONCAT(CAST(rocks AS CHAR) ORDER BY _date DESC), ',', 1 ) as bottom

FROM database

MySQL, loading fixed width file

LOAD DATA INFILE '/tmp/test.txt'
INTO TABLE table(@var) SET
name=Trim(SUBSTR(@var,1,24)),
something=Trim(SUBSTR(@var,25,4)),
else=Trim(SUBSTR(@var,29,3));

The first number is the starting row, the second number is the length of the field. @var in this example is a randomly named variable. Name, something & else describe the database column(s).

Executing a PHP script every few seconds

Open /etc/crontab with VI and add lines similar to the ones seen below. Make sure to use <tab> instead of spaces!

* * * * * root php /your/file/location.php > /dev/null 2>&1
* * * * * root sleep 10; php /your/file/location.php > /dev/null 2>&1
* * * * * root sleep 20; php /your/file/location.php > /dev/null 2>&1
* * * * * root sleep 30; php /your/file/location.php > /dev/null 2>&1
* * * * * root sleep 40; php /your/file/location.php > /dev/null 2>&1
* * * * * root sleep 50; php /your/file/location.php > /dev/null 2>&1

 

Restart cron deamon using the command show in this post.

Back to Top