Friday, March 30, 2012

Scroll page with javascript

Sometimes it's useful to scroll the page automatically to send users to certain parts of the page. To do that the easiest way is using javascript, more specifically jquery that is a javascript framework.

Test it here:

Scroll down!
 
Example code:

<html>
<head>
<SCRIPT LANGUAGE="JavaScript" 
SRC="https://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js">
</SCRIPT>
<SCRIPT LANGUAGE="JavaScript">
function scroll_up()
{
    $(window).scrollTop(0);
}
function scroll_to_last_div()
{
    $(window).scrollTop($('#last_div').offset().top);
}
</SCRIPT>
</head>
<body>
<center>
<div style="height:100px;width:400px;">
<br><br>
<a href="javascript:scroll_to_last_div();">Scroll to last div!</a>
</div>
<div style="height:600px;width:400px;background:#234a34;">
</div>
<div style="height:100px;width:400px;" id="last_div">
<br><br>
<a href="javascript:scroll_up();">Scroll to top!</a>
</div>
<div style="height:600px;width:400px;background:#fa342a;">
</div>
</center>
</body>
</html> 

Monday, March 19, 2012

Insert one or multiple rows in mysql db using php

Normally, one of the first thing that you need to do after connect to a mysql database is insert data. This tutorial is about inserting a single row or multiple rows into a mysql database using php. If you don't know how to connect to a database check our previous tutorial "Connect to a mysql database using php".

Let's imagine for this example that my table name is "people" and inside this table i have 3 columns "id", "first_name" and " last_name".

This way to insert a single row with the person "Chuck Norris" i need to execute the following query:

$validation = mysql_query("INSERT INTO platform_types 
                         (id, first_name, last_name) 
                         VALUES ('1', 'Chuck', 'Norris')"
                         ,$db_con);

if (!$validation) //test query for errors 
{
    echo("Error in query: " . mysql_errno($apbl_db_con) . ": " 
    . mysql_error($apbl_db_con) . '
');             
}
//Closing connection (don't forget to close the connection 
//when you don't need to query stuff to the db)
apbl_db_close($apbl_db_con); 

The $db_con variable is the one returned by mysql_connect when you connect to the database. If you need to insert multiple rows at same time the procedure is the same but you add more values at the end like this:

$validation = mysql_query("INSERT INTO platform_types 
    (id, first_name, last_name) VALUES 
    ('1', 'Chuck', 'Norris'), 
    ('2', 'Jackie', 'Chan')",$db_con);

//...the rest of the code it's the same.
 Notice that if your "id" column is set to auto-increment (usually is) you don't need to give a value to the "id" in the query because it will auto-increment by him self. Then your query will look like this:

$validation = mysql_query("INSERT INTO platform_types 
    (first_name, last_name) VALUES 
    ('Chuck', 'Norris'), 
    ('Jackie', 'Chan')",$db_con);

//...the rest of the code it's the same.

Thursday, March 15, 2012

Connect to a mysql database using php

In almost all web projects now a days you need to use at least one database to store information. So let's start using a database! First step is to connect to the database.
For this example let's imagine that a i have mysql running on the adress "localhost" with the username "root" and password "password". The database name is "mydatabase".

With this information we can start coding our php script to connect with the database.


I hope it has been helpful, in the next tutorial let's see how to insert data on your  mysql database using php.

        
//Try to connect to database
$con = mysql_connect('localhost','root','password'); 
      
if (!$con) //Test if connection was successfully
{
    echo ('Error on connect: ' . mysql_errno() . ": " 
    . mysql_error());
}
else
{
    //Connect to the table inside the database
    $db_check = mysql_select_db('mydatabase', $con); 
    if (!$db_check)
    {
        echo ('Error on the database : ' . mysql_errno() 
        . ": " . mysql_error());
    }
}

Next tutorial:  "Insert one or multiple rows in mysql db using php".

Sunday, March 11, 2012

ShutItDown RBS Review

Following my last post about licensing free and open source software, today i will review on of my applications that i just released for free under the GNU GPL v3 license. Both the application and the code written in Visual Basic are available to download.

ShutItDown RBS


ShutItDown RBS is a software that allows the user to schedule task like shut down, restart or log off on his machine. You can specify date and time and even specify if you want them to repeat every day or every week.

Features:
  • Quickly shut down, restart or log off your pc.
  • Schedule shut down, restart or log off tasks in your pc.
  • Able to run minimized and start automatically with windows.
  • You can schedule daily or weekly tasks and they will be performed automatically until you disable them.
  • Automatically generated log of ShutItDown activities so that you can check if certain tasks were performed.


shutitdown free and open source


User guide video:






This software was already approved in several websites like softpedia.com, freewarefiles.com, majorgeeks.com and soft82.com.

So if you are into programming and sometimes you develop some applications, why not share them with world?


Links:
ShutItDown RBS website 
ShutItDown RBS sourceforge project