Archive

Posts Tagged ‘PHP’

Free Zipcode Database

July 17th, 2009 Arthur Gressick No comments

I am working on a project for looking up distances from zipcodes. I found an open source database and some other information for making this happen. I will post more on this when I get it completed.

http://zips.sourceforge.net/

Also take a look at this site.

http://www.populardata.com/ (you can find the canadian DB from there)

Good luck and I will post a bunch of information on this page when I am finished.

Categories: Databases, PHP Tags: , ,

Using the jQuery Cycle Plugin

February 25th, 2009 Arthur Gressick 1 comment

Recently I had to do a small project that involved creating a learning tool – virtual flash cards. I used the jQuery plugin Cycle to provide the animation effects for the “stack” of cards and I also used another jQuery plugin called quickFlip.

Basically I created a way for the user to grab a glossary from a specific course and then I used php and mysql to loop through the results each time generating the following div tags:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
<div class="quickFlip">
<!-- Front of card -->
<div class="quickFlipPanel front-card">
    <h4 class="">
       <p class="quickFlipCta" style="text-align: center; color: #ff0000;">Click here to flip the card over.</p>
    </h4>
</div>
 
<!-- Back of card -->
<div class="quickFlipPanel back-card">
    <h4 class="">
      <div style="text-align: center; width: 615px; height: 100px;">
        <div>
          <h3>Correct</h3>
        </div>
        <div>
          <h3><a>Incorrect</a></h3>
        </div>
      </div>
    </h4>
</div>

Here is the javascript function defined for update_correct and update_incorrect:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
var correct_count = 0;
var wrong_count = 0;
function update_correct(pos) {
    correct_count = correct_count + 1;
    document.getElementById("number-correct").innerHTML = correct_count;
    var t = quickFlip.flip(pos, 1, 1);
}
 
function update_incorrect(pos) {
    wrong_count = wrong_count + 1;
    document.getElementById("number-wrong").innerHTML = wrong_count;
    var t = quickFlip.flip(pos, 1, 1);
}
 
function show_results() {
    $("#num_correct").html('You got ' + correct_count + ' right.');
    $("#num_wrong").html('You got ' + wrong_count + ' wrong.');
}

jQuery cycle plugin – http://malsup.com/jquery/cycle/
jQuery quickFlip plugin – http://jonraasch.com/blog/quickflip-jquery-plugin

PHP CLI FTP uploader

February 21st, 2009 Arthur Gressick No comments

So I wanted to create a automated FTP uploader for the project I was working on. I set a CRONTAB to execute it and then hooked up a database as well. 

Here is the code:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
#!/usr/bin/php -q
<?php
#script used for uploading file to a server
//------ Begin Programming
 
$ftp_server = "subdomain.server.com";
$ftp_retries = "5";
$ftp_delay = "3";
$ftp_user = "user";
$ftp_pass = "password";
 
//This worked on the server
$source_directory = "/home/user/videos/flv/";
$remote_directory = "/httpdocs/movies/";
 
//mysql connection
define ('DB_User', 'user');
define ('DB_Password', 'password');
define ('DB_Host', 'x.x.x.x');
define ('DB_Name', 'db_name');
 
$dbc = mysql_connect (DB_Host, DB_User, DB_Password) OR
die ('Could not connect to MySQL Server: ' . mysql_error() );
mysql_select_db (DB_Name) or
die ('Could not select the database: ' . mysql_error() );
 
//do a query
$sql_query = "your query";
$result = @mysql_query ($sql_query);
$videos = mysql_fetch_array ($result, MYSQL_ASSOC);
$counter = mysql_num_rows($result);
 
if ($counter &gt; 0) {
 
//mark the as processing
$sql_query = "UPDATE SCRIPT";
$result = @mysql_query ($sql_query);
 
//
$conn_id = ftp_connect($ftp_server);
 
$login_result = ftp_login($conn_id, $ftp_user, $ftp_pass);
 
$source = $source_directory.$videos['processed_file'].".flv";
$remote = $remote_directory.$videos['processed_file'].".flv";
 
if (ftp_put($conn_id, $remote, $source, FTP_BINARY)) {
//            echo "successfully uploaded $source\n";
} else {
//mark file to reupload again
$sql_query = "UPDATE SCRIPT";
$result = @mysql_query ($sql_query);
//            echo "There was a problem while uploading $source to $remote\n";
}
 
 // Close connection
ftp_close($conn_id);
}
?>

Categories: PHP, PHP CLI, Ubuntu 8.x Server Tags: , , , ,