set php code to be run in the future

Sometimes you may need a code which should be run in certain date interval. No, i don’t mean whole php file, for that there is a technology called “Cron Jobs”. I mean code fragment in your existing PHP project. For example you want you background to be red after 23:59. Or at 31st decebmer night you want some “happy new year” banner to be appear for 1-2 hours. Or you just creating some scheduled event module and this logic can help you build it. Let’s write this simple trick. Continue reading →

Today i had to solve one little bug in one web site. So i want to share it, may be it will be needed by you in the future. I will explain it in example. So, we have a table called “LessonParts” and one of its columns “Part” column contains elements as “Test 1”, “Quiz 2”, “Exercise 14”, “Test 3”, “Quiz 24” and etc. And let’s consider that they all are parts of lessons.(Lesson N contains [Test N, Quiz N, Exercise N…]) If you want to see it in action, you can use sample table.

DROP TABLE IF EXISTS `LessonParts`; CREATE TABLE `LessonParts` ( `ID` int(11) NOT NULL AUTO_INCREMENT, `Name` varchar(200) NOT NULL, `Part` varchar(30) NOT NULL, `Content` text NOT NULL, PRIMARY KEY (`ID`) ) ENGINE=MyISAM AUTO_INCREMENT=4 DEFAULT CHARSET=latin1; INSERT INTO `LessonParts` (`ID`, `Name`, `Part`, `Content`) VALUES (1, 'Name 1_1', 'Exercise 1', 'Content here'), (2, 'Name 1_2', 'Test 1', 'Content here'), (3, 'Name 1_3', 'Quiz 1', 'Content here'), (1, 'Name 2_1', 'Exercise 2', 'Content here'), (2, 'Name 2_2', 'Test 2', 'Content here'), (3, 'Name 2_3', 'Quiz 2', 'Content here'), (1, 'Name 3_1', 'Exercise 3', 'Content here'), (2, 'Name 3_2', 'Test 3', 'Content here'), (3, 'Name 3_3', 'Quiz 3', 'Content here');

And now we need to get some sorted information about this table. For example: 1. We need to get maximum number of lessons.

$qnet=mysql_query("select CAST(SUBSTRING_INDEX(`Part`,' ',-1) AS UNSIGNED INTEGER) as numb from LessonParts ORDER BY numb desc limit 1"); $result=mysql_result($qnet,0,'numb'); echo $result;

2. We need to get lesson 4 parts for fetching it.

$qnet=mysql_query("SELECT Name,Part,Content,SUBSTRING_INDEX(Part,' ',-1) as alfa FROM LessonParts WHERE alfa=4 ;"); echo '<h3>Lesson 4</h3>'; while ($row=mysql_fetch_array($qnet)) { echo '<p>'.$row[0].'</p>'.$row[2].'<br><br>'; } $result=mysql_result($qnet,0,'numb');

That’s all. Of course it is better to keep part number and part type not in one column(“Exercise 1”), it is better to create two columns and to keep it separated. But if no way, if the table already exists, you just have to get result, then our example will solve your problem.

İn this post i will give a small php code for wordpress which displays your wordpress categories in a nice pie-chart. It might be useful for every blog which owner is interested to share statictics of his(her) blog. This is code solution of this small task:

//Author: Elvin Haci //Author url: $ch_cats = get_categories(array('orderby'=>'count','order'=>'desc') ); $sayy= count($ch_cats); $chd=''; $chl=''; for ($i=1;$i<=$sayy;$i++) { $chd=$chd.','.$ch_cats[$i-1]->count; $chl=$chl.'|'.$ch_cats[$i-1]->name.'('.$ch_cats[$i-1]->count.')'; } $chd=substr($chd,1); $chl=substr($chl,1); $ch_title="My blog categories by post count"; $ch_size="450x200"; // You can change it feet to your post echo '<img src="'.$ch_title.' &cht=p3&chd=t:'.$chd.'&chs='.$ch_size.'&chl='.$chl.'">';

If you want to place pie chart into your post or page, you must install InlinePHP at first. After install you will be able to execute php codes inside posts. You can put this code into any post, with phpinline tag [ exec ] …code here… [/exec] But if you have enough practise working with theme editor, you can put this php code to any place of your theme, for example to sidebar widget(sidebar.php in your theme folder). At the end i show you the result of this code(i place inside blog post, it means that i have used phpinline plugin for it), of course here it shows categorie-chart for :). [exec] $ch_cats = get_categories(array(‘orderby’=>’count’,’order’=>’desc’) ); $sayy= count($ch_cats); $chd=”; $chl=”; for ($i=1;$icount; $chl=$chl.’|’.$ch_cats[$i-1]->name.'(‘.$ch_cats[$i-1]->count.’)’; } $chd=substr($chd,1); $chl=substr($chl,1); $ch_title=”My blog categories by post count”; $ch_size=”450×200″; // You can change it feet to your post echo ‘‘; [/exec] I can easily turn this code to new wordpress plugin if users who don’t like any coding need it. Good luck. If any question, please don’t hesitate to write comment.

Face detection has been very interesting topic for me since i heard about it. I am working on new plugin which will use face detection. Now i share two easy to use php and jquery face detection classes:

1. PHP face detection class

Download page

2. Jquery face detection script

Download page