« November 2009 »
Sun Mon Tue Wed Thu Fri Sat
1 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        

November, 2009


Maxims
Date : 11-19 20:12:
Views: 1748
Comments : 0
Topic :Aphorisms
Aphorisms
Date : 11-17 13:25:
Views: 1017
Comments : 0
Topic :Aphorisms
Review of The Lexicographer's Dilemma
Date : 11-03 19:51:
Views: 5316
Comments : 0
Topic :Books


gpullman@gsu.edu
Published: 08-25 2007
Title: Auto Columns
Topic: PHP

<?

$sql = "SELECT * FROM users order by fname";

$query = mysql_query($sql4)
        or die("Can't find student.");

$columns = 4;

$num_rows = mysql_num_rows($query4);

echo "<tr><td colspan=4><B>name</B>: </td></tr>";

// a for loop so we can use the number of rows

for($i = 0; $i < $num_rows; $i++) {
    $row = mysql_fetch_array($query4);
    if($i % $columns == 0) {
        //if there is no remainder, we want to start a new row
        echo "<TR>";
    }
    echo "<TD width=20%>   </td>";

 if(($i % $columns) == ($columns - 1) || ($i + 1) == $num_rows) {
        //if there is a remainder of 1, end the row
        //or if there is nothing left in our result set, end the row
        echo "</TR>";
    }
}

 echo "</table>";
  




Published: 04-13 2007
Title: Image Randomization
Topic: PHP

(link)
<?php

//By Angela Bradley for PHP @ About.com
 

//Assign the image and link URLs here, you can add more following this formatt

$Img1 = "http://goat.ws/board/images/avatars/114693804644304f35a8399.jpg";
$Url1 = "http://www.goat.ws";

$Img2 = "http://goat.ws/board/images/smiles/gamesc.gif";
$Url2 = "http://www.identity.st";

$Img3 = "http://goat.ws/board/images/avatars/11415438874159139eaacbe.gif";
$Url3 = "http://php.about.com";


//Leave the first number as 1, and set the second to how many banners you have
$num = rand (1,3);

//This creates the variables
$Image = ${'Img'.$num};
$URL = ${'Url'.$num};

//This actully outputs the banner
Print "<a href=".$URL."><img src=".$Image." border=0></a>";

?>



Published: 04-11 2007
Title: Switch snippet
Topic: PHP

<?php switch($id)
{
case ’intro’:
 include ’intro.php’;
 break;
case ’bluetruck’:
 include ’bluetruck.php’;
 break;
case ’redhouse’:
 include ’redhouse.php’;
 break;
case ’brownbear’:
 include ’brownbear.php’;
 break;
default:
 require ’intro.php’;
}
?>

<ul>
<li><a href="main.php?id=intro" title="Page intro">Intro</a></li>
<li><a href="main.php?id=bluetruck" title="Blue Truck">Blue Truck</a></li>
<li><a href="main.php?id=redhouse" title="Red House">Red House</a></li>
<li><a href="main.php?id=brownbear" title="Brown Bear">Brown Bear</a></li>
</ul>

link




Published: 11-15 2005
Title: Deadline enforcer
Topic: PHP

One of the advantages to having writing assignments done online is that you can more easily enforce deadlines. The basic idea is compare the current time to a deadline and branch when deadline = now. The easiest way is to do something like:

$now = date(Y - f - d);
$deadline = (2005 = 11 -15);

if ($deadline - $now < 0){
Print "some time remaining"";
}
else
print "past due";

The problems with this approach are numerous, but include the fact that hours are not part of the equation.

Here is a better way,

<?
function dateTimeDifference($today,$due){
$diff = (strtotime($today)-strtotime($due));
return $diff;
}

function second2min($arg){
$convers = ceil($arg/60);
return $convers;

}

print "It is now :<BR>";
echo $today = date("Y-n-j h:i")." ";
echo date("a");    
print "<br>";
print "This assignment is due : <br>";
echo $due = "2005-11-15 12:00 pm";

$d =  dateTimeDifference($due,$today);

if($d <="0"){
print "<P>This assignment is past due.";
exit;
}
else


$hours = round(second2min($d)/60,1);
echo "<BR>roughly $hours hours left";

print "<h3>Instructions</h3> ";


 

 

 




Published: 10-02 2005
Title: Cron job
Topic: PHP

Good article at Sitepoint about using cron job and php. (link)


Published: 09-22 2005
Title: Pulling content from a db
Topic: PHP

$query = "SELECT * FROM TABLE";
$result = mysql_query($query)
    or printf ("Error creating database: %s\n", mysql_error ());
 while ($item = mysql_fetch_array($result, MYSQL_ASSOC)) {
 
  foreach ( $item as $col_value) {
    echo $col_value;}

}

OR

while(list($name,$etc)=mysql_fetch_row($result)){
echo $name, $etc.}

 




Published: 09-21 2005
Title: Scheduling software
Topic: PHP

I've looked unsuccessfully for some time now for a php script that would enable my colleagues and I to find mutual meeting times. Finally I've written my own. If there is an ugliest code competition, it could win. But it does work. You will need a php and mysql enabled webserver. The two files, the php and the sql db setup file are zipped here.

It occurs to me that this software might be more useful if it had a javascript calendar that would allow the organizer to sellect the week, since any given week is  bound to have anomolies.




Published: 09-21 2005
Title: Redirect
Topic: PHP

print "<meta http-equiv='refresh' content='1;  url=http:file.php' />";



Published: 09-19 2005
Title: loop through an array
Topic: PHP

<?php
foreach($arrayname as $key=>$value
)
    {
    echo
$key.": ".$value
;
    }
?>



Published: 05-03 2005
Title: CSS skinner
Topic: PHP

0
<?
1
$skin = (isset($_GET['skin']) ? $_GET['skin'] : '1');
2
if(
$skin=='1') {
3
setcookie('skinid', 1);
4
} elseif(
$skin==2) {
5
setcookie('skinid', 2);
6
}
7
?>
8
<?
9
$skinid
= $_COOKIE['skinid'];
10
if(
$skinid==1) {
11
include
"css.css";
12
} elseif(
$skinid==2) {
13
include
"css2.css";
14
} elseif(
$skinid=='') {
15
include
"css.css";
16
}
17
?>

(link)


Published: 05-22 2004
Title: php graphics
Topic: PHP

I need to learn how to represent data graphically so that i can report the findings of the 1101-T tech survey to APACE. I've found a useful chapter in the PHP5MYSQL Bible, and the basic idea is represented at bar_graph_form.php




Published: 05-18 2004
Title: print a list of a db's field names
Topic: PHP

$fields = mysql_num_fields($result);
$rows  = mysql_num_rows($result);

for ($i=0; $i < $fields; $i++) {
  // $type  = mysql_field_type($result, $i);
   $name  = mysql_field_name($result, $i);

print "$name<br>";
}




Published: 05-08 2004
Title: Print all variables
Topic: PHP

This snippet will print all of the variables as name value pairs. Handy for showing the user what they entered.

// Print POST Variables 
 echo "
";
 
 echo "POST Variables from $HTTP_POST_VARS

";
  reset($HTTP_POST_VARS);
   while (list ($key, $val) = each ($HTTP_POST_VARS)) {
  print $key . " = " . $val . "
";
 }

If you replace the previous print statement with this:

 print "$". $key .",";

you get a string of comma seperated variables like this:

$name,$phone,$email,

You could then assign that string to a variable for a msql statment.

Well, no actually, you can't. the problem that i can't solve is that the msqyl value statement can't end with a comma and every way i tried to remove it failed. So I'm still looking.




Published: 05-08 2004
Title: Multiple form select
Topic: PHP

(link)

 

multiple_select.htm
===========

<html>
<head>
       <title>PHP Forms Example</title>
</head>
<body>
<FORM action="multiple_select.php" method=POST>
Which programming languages would you like to learn?<br>
<select name="myGoals[]" multiple>
<option value="PHP" SELECTED>PHP</option>
<option value="Perl">Perl</option>
<option value="JavaScript">JavaScript</option>
<option value="Python">Python</option>
<option value="Ruby">Ruby</option>
</select><br>
<input type="submit" name="languages" value="Submit"><br>
</form>
</body>
</html>

multiple_select.php
===========

<?php
   print "You are interested in: ";
   foreach($myGoals as $value)
   {
      print "$value ";
   }

?>

OUTPUT:

You are interested in: PHP Perl Python




Published: 04-24 2004
Title: cache prevention
Topic: PHP

<?php
header("Cache-Control": no-cache, must revalidate");
header("Pragma: no cache");
header("Expires: Mon,26 Jul 1997 05:00:00 GMT");
?>


Published: 04-15 2004
Title: PHP forms automator
Topic: PHP

I found this code at Zend. It automates the process of creating a form by transforming a string of names into textboxes with names and values set to whatever you put in the string. So all you have to do is come up with your lables for the form and it makes the form. I was thinking about making something like this to make webforms to mysql dbs more efficiently. It won't do the mysql part, but it could be hacked to, i think. 

<?php

        // copyright  ©  2000-2002 ilija injac injac@article-24.com
        // Authors: ilija injac
    
    class formwizard
    {
        //Members
        var $_formFields;         //Variable holding the names of the formfields
        var $_formValues;         //Variable holding the values of the fields (for edit forms)
        var $_formName;              //Variable holding the name of the form
        var $_formAction;        //Variable holding the form action
        var $_formMethod;        //Get or Post Form ?
        var $_fieldCaptions;    //The captions for the forms
        var $_isInsertForm;     //is the form a insert form ?
        var $_nil;                //a tempvar
        
        //constructor
        function formwizard($formFields,$formName,$formAction,$formMethod,$fieldCaptions,$formValues="")
        {
            //init Members
            $this->_formFields         = $formFields;
            $this->_formName        = $formName;
            $this->_formAction        = $formAction;
            $this->_formMethod      = $formMethod;    
            $this->_fieldCaptions    = $fieldCaptions;
            
            //check if edit or add form
            if($formValues == "")
            {
                //this is a insert form
                $this->_isInsertForm = true;
                //get the values for the form elements
                $this->get_insert_form_properties();
            }else
            {
                //this is a edit form
                $this->_isInsertForm     = false;
                //insert member for form values
                $this->_formValues         = $formValues;
                //get the values for the form elements
                $this->get_edit_form_properties();
            }
                        
        }
        
        //get values for form fields, if edit form
        function get_edit_form_properties()
        {
            
            //get the form names
            $this->_nil = explode("|",$this->_formFields);
            //exchange the value
            $this->_formFields = $this->_nil;
            
            //get the form values
            $this->_nil = explode("|",$this->_formValues);
            $this->_formValues = $this->_nil;
            
            //get the field captions
            $this->_nil = explode("|",$this->_fieldCaptions);
            $this->_fieldCaptions = $this->_nil;
            
        }
        
        //get field names for form fields, if insert form
        function get_insert_form_properties()
        {
            //get the form names
            $this->_nil = explode("|",$this->_formFields);
            //exchange the value
            $this->_formFields = $this->_nil;    
                        
            //get the field captions
            $this->_nil = explode("|",$this->_fieldCaptions);
            $this->_fieldCaptions = $this->_nil;
        }
        
        
        function print_form()
        {
            
            echo "<form name=\"$this->_formName\" method=\"$this->_formMethod\" action=\"$this->_formAction\">";
            echo "<table border=0 cellspacing=0 cellpadding=3>";
            
            //check if insert or update form
            if($this->_isInsertForm)
            {
                //insert form
                foreach($this->_formFields as $key => $value)
                {
                    
                    echo "<tr><td>".$this->_fieldCaptions[$key]."</td><td><input type=\"text\" name=\".".$this->_formFields[$key]."\"></td></tr>";
                }
                
                echo "<tr><td><input type=\"submit\" value=\"go\"></td><td><input type=\"reset\" value=\"reset\"></td></tr>";
                echo "</table>";
                echo "</form>";
            }else
            {
                //update form
                foreach($this->_formFields as $key => $value)
                {
                    echo "<tr><td>".$this->_fieldCaptions[$key]."</td><td><input type=\"text\" name=\".".$this->_formFields[$key]."\" value=\"".$this->_formValues[$key]."\"></td></tr>";
                }
                echo "<tr><td><input type=\"submit\" value=\"go\"><td>&nbsp;</td></tr>";
                echo "</table>";
                echo "</form>";
            }            
            
        }
        
        
    }


//include("lib/form_wizard_class.inc");
    
    $fields     = "name|vorname|strasse|plz|ort";
    $captions    = "Name|Vorname|strasse|Plz|Ort";
    $values        = "Injac|Ilija|blubb|33323|blubb";
    
    //edit form
    $form1    = new formwizard($fields,"testform","test.php","post",$captions,$values);
    $form1->print_form();
    //insert form
    $form2    = new formwizard($fields,"testform","test.php","post",$captions);
    $form2->print_form();  


?>




Published: 04-13 2004
Title: msword cleaner?
Topic: PHP

In the process of building online writing tools i've repeatedly come up against problems created by ms-code when people cut from a word file and paste into a form. There are methods for dealing with this. I found one at chuggnutt.com. I put an example in the fyc directory under clean.php. I'm not sure it does what I want because it seems to remove too much formatting but I need to work with it further.


Published: 04-13 2004
Title: user logs
Topic: PHP

There's a nice tutorial over at phpfreaks about building a log script.

<?php
session_start
();
if(!
session_is_registered('counted'
)){
    
$agent = $_SERVER['HTTP_USER_AGENT'
];
    
$uri = $_SERVER['REQUEST_URI'
];
    
$user = $_SERVER['PHP_AUTH_USER'
];
    
$ip = $_SERVER['REMOTE_ADDR'
];
    
$ref = $_SERVER['HTTP_REFERER'
];
    
$dtime = date('r'
);
    
    if(
$ref == ""
){
        
$ref = "None"
;
    }
    if(
$user == ""
){
        
$user = "None"
;
    }
    
    
$entry_line = "$dtime - IP: $ip | Agent: $agent  | URL: $uri | Referrer: $ref | Username: $user n"
;
    
$fp = fopen("logs.txt", "a"
);
    
fputs($fp, $entry_line
);
    
fclose($fp
);
    
session_register('counted'
);
}
?> 
 




Published: 04-03 2004
Title: Excellent php help
Topic: PHP

I don't know why i didn't notice this before, or if i did why i didn't register it, but w3schools, which is excellent for css is also pretty handy for php.


Published: 04-03 2004
Title: form checking
Topic: PHP

I think the following code could be use to check if fields have been left blank.

if ($name == "" || $email == "" || $password == "") {
echo "Please fill in all the fields";
}

Haven't checked it yet, though.




Published: 01-20 2004
Title: Automate mysql Insert directives
Topic: PHP

A script called Echelon SQL perports to create the values $ pairs on the fly so that to put form contents into a db, all you hae to do is create the form with name="name" and the tables with the same names and connect the form to the db. Echelon stuffs the content.

I haven't used it yet as i can't untar from the machine I'm on, but I'm eager to try it out.

http://www.digitalthought.net/sections.php?op=viewarticlesp&artid=3

 




Published: 01-13 2004
Title: php tutorials
Topic: PHP

An excellent collection of turorials on various methods related to forms, files, counters, etc. (link)


Published: 01-11 2004
Title: Date transformation
Topic: PHP

Problem: date is in 2004-01-31 format and you want it printed as January 31 2004.

Solution:

$test = explode("-",$date);
 
 $y = $test[0];
 $m = $test[1];
    $d = $test[2];

// Generate the month text for the numbers (returns a string)
function genMonth_Text($m) {
 switch ($m) {
  case 1: $month_text = "January"; break;
  case 2: $month_text = "February"; break;
  case 3: $month_text = "March"; break;
  case 4: $month_text = "April"; break;
  case 5: $month_text = "May"; break;
  case 6: $month_text = "June"; break;
  case 7: $month_text = "July"; break;
  case 8: $month_text = "August"; break;
  case 9: $month_text = "September"; break;
  case 10: $month_text = "October"; break;
  case 11: $month_text = "November"; break;
  case 12: $month_text = "December"; break;
 }
 return ($month_text);
}

//applies the above function to the month created by explode above $m = genMonth_Text($m);

echo "$m $d $y";




Published: 12-21 2003
Title: heredoc command
Topic: PHP

when writing php enabled webpages, it's tedious to have to write the html inside print statements and to remember to escape everything prperly. An alternative is to use the heredoc command. Everything between <<<EOD  and EOD is leteral, plain html.

<?PHP
$mystring
= <<<EOD
Hello World!
This is the second line!
EOD;
?>

 




Published: 12-16 2003
Title: deadline imposer
Topic: PHP

Below is a script that reads a date from a file and compares it to today's date and then decides what to display based on whether today's date is greater than or equal to it.

<?

$cuttoff = "deadline.txt";
$fp = fopen($cuttoff, "r+");
$cuttoff = fread($fp, filesize($cuttoff));


// date must be formatted as Month day number, yyyy -- December 17, 2003

 

$today = (Date('F d, Y'));

if($today <= $cuttoff){

echo "I'm sorry. The deadline for this semester has passed. Please comeback next semester.";

}
else
echo "wooho!";

?>




Published: 11-21 2003
Title: Forms -- action = self
Topic: PHP

To reduce the number of php files, execute a form's action statement from
within the form itself.
<?

if ($submit) {

// process form

}

?>


<FORM name=form1 action="<?php echo $PHP_SELF ?>" method="post "><BR></P>
<INPUT type=submit value=Go! name=submit>
</form>

Remember to name the submit button submit. And use $_GET['value']; instead of $_POST




Published: 11-16 2003
Title: Averaging Data
Topic: PHP

This should be cross listed with mysql. After gathering data from a form and putting the responces into a db, I used this script to extract the numbers from a field, average them and then print them rounded to two decimal places. It's a bit clumsy because the number of entries is hard coded (45). it would be better if the script first added the number of entries on the ID field and then used that number as the divisor for the average.

$query="SELECT sum(FIELD) FROM study";
$result = mysql_query($query)
or printf ("Error creating database: %s\n", mysql_error ());

$num = mysql_result($result,0,0);

$div = "45";

$average = $num / $div;

print round($average, 2);




Published: 11-15 2003
Title: Printing data
Topic: PHP

I used this script to pull info from a db and print it to the screen. The $field<0 keeps it from printing empty entries. 

 

<?
$query="SELECT FIELD NAME  FROM DATABASENAME";
$result = mysql_query($query)
    or printf ("Error creating database: %s\n", mysql_error ());

// Printing results in HTML

while ($get_info = mysql_fetch_row($result)){
foreach ($get_info as $field)
if($field < '0' ) {
print "";
}
else

print "$field<br><br>";
}

?>




Published: 11-02 2003
Title: Group email from db
Topic: PHP

connect to db

// create SQL statement
$sql = "SELECT email FROM members";

$result = mysql_query($sql,$connection)
        or die("Couldn't execute query.");


$email = '';
 while($row = mysql_fetch_array($result))
 {
     $email .= $row["email"].',';
 }
$email = substr($email, 0, strlen($email) - 1);


//email message

$update = "Hello Curriculum Committee Members:\n\n";
$update .= "$title<br> \n\n";
$update .= "$body \n\n";

mail("$email", "A&S Curriculum Committee",$update, "From: gpullman@gsu.edu");
?>




Published: 10-28 2003
Title: Writing form to file
Topic: PHP

// The next line opens a file handle to a file called form.htm

// for it to work you have to have a file called file.htm in the same directory with permissions set to 755


$out = fopen("file.htm", "a");
 
// if the file could not be opened for whatever reason, print
// an error message and exit the program

if (!$out) {
    print("Could not append to file");
    exit;
}

// fputs writes output to a file.  the syntax is where to write
// followed by what to write
// \t represents a tab character and \n represents a new line


fputs($out,"$name\t");
fputs($out,"$email\t");
fputs($out,"$REMOTE_ADDR\n");
print("Thanks");

fclose($out);

?>
 




Published: 10-02 2003
Title: getting all variables from a form at once
Topic: PHP

@extract($_POST);

apparently reads all of the name=value pairs into an array. (link)




Published: 09-24 2003
Title: Code for printing file backward
Topic: PHP

I used this to print a most recently updated blogs file to the screen:

<?

$lines = file('updates');
krsort($lines);
reset($lines);
foreach($lines as $key=>$line){
echo "$line
";


?>

The content of "updates" is provided by a simple form to file script that prints a line of text for each entry, including  link to the blog. It's not very sophisticated but it does work. The script above reads a file into an array (file has to have entry per line) and then reverse sorts the array by key rather than value.

 




Published: 08-26 2003
Title: Turorial Site
Topic: PHP

A site with helpful tutorials, including a regular expression snippet collection that can be used to validate phone numbers, email addresses, etc. (lnik)


Published: 08-18 2003
Title: Date formatting
Topic: PHP

A typical application of the date command in php would be <?php print date("Y:m:d H:i") ?>. The colons are purely visual elements. 

Here is a table naming and describing the php date codes. (link

 




Published: 06-04 2003
Title: Calendar navigation code
Topic: PHP

I've been looking some time now for a good explanation of a calendar navigation scheme, liek those used in blogs. Devarticles.com has a calendar tutorial that's very easy to follow. It writes to a text file innstead of a db. That wold be perhaphs easy to change but it might also be preferable to leave it the way it is. (link to my example)


Input
Admin
Add
Email updates



Links

Aldaily
Blogrunner
Books24/7
Digg
Gizmodo
Google News
Inform
Internet news
LifeHacker
News Now UK
News Wire
Overheard NYC
Reddit
rhetcomp
Sifry's Alerts
Web Dev Hndbk
Webcreme

Topics
8123 (47)
adult literacy (20)
Aphorisms (8)
Blogging (81)
Blogging & Teaching (3)
Blogging History (0)
Blogging Software (16)
Books (34)
CMS (5)
commonplaces (22)
Composition (9)
critical thinking (3)
CSS (33)
CTW (3)
DTP (2)
E-texts (1)
Epolitics (2)
Home Repair (1)
InfoVis (2)
Java (0)
Javascript (3)
misc (29)
MySQL (1)
news (1)
Open source (3)
PHP (35)
PR (2)
QEP (3)
rhetoric (39)
Robotic grading (6)
RSS (6)
Social Software (2)
Software (9)
Teaching (15)
Usability (2)
Writing (41)