HOME

FORUM

UPLOAD SOURCE

RPGLE/RPG

CLLE

SQLRPGLE

DDS

API

OTHER

JAVA

IFS

HTML

JAVA SCRIPT

PHP

MYSQL

XML

OLE DB




    PHP  - include function
Posted By: JimmyOctane   Contact

A nice feature of PHP is the include.
This allows you to create one navigation/header
page and include it in all pages of your website.
the format is


include("includes/head.php");

In this case I have created a folder
called includes. I store all my includes
here.


    PHP  - Define a variable
Posted By: JimmyOctane   Contact

//define variable timestamp
$timestamp=mysql_result($result,0,"time");
// seconds in one day = 60 * 60 * 24 = 86400
// seconds in one hour= 60 * 60 = 3600
$hour = 3600;
$Seconds30 = 30;

    PHP  - Validate email address with eregi
Posted By: JimmyOctane   Contact

else if( !eregi("^[a-z0-9]+([_\\.-][a-z0-9]+)*". "@([a-z0-9]+([\.-][a-z0-9]+))*$",$email) )
// okay not a good email
{
$Email_Error = '&nbsp;&nbsp;<font size=1 color=#FF0000>!&nbsp;Please enter valid email address.</font>';<br>
$Screen_Error = 'Y';
}

    PHP  - PHP connection string
Posted By: JimmyOctane   Contact
MySQL Example
The most common database used with PHP is MySQL, so I guess you should be familiar with
the following code. It connects to a MySQL server at localhost, database mydb, and executes
an SQL select statement. The results are printed, one line per row.


$db = mysql_connect("localhost", "root", "password");
mysql_select_db("mydb",$db);
$result = mysql_query("SELECT * FROM employees",$db);
if ($result === false) die("failed");
while ($fields = mysql_fetch_row($result))
{
for ($i=0, $max=sizeof($fields);
$i < $max; $i++) {
print $fields[$i].' ';
}
print "<br>\n";
}


    PHP  - Calendar
Posted By: JimmyOctane   Contact

?>
<style type="text/css">
<!--
td
{
font-size:12pt;
line-height:14pt;
font-family:Helvetica,Arial;
}
//-->
</style>

<?

## change to the previous month
if ($command == "prev_month")
{
if (--$month == 0)
{
$month = 12;
$year--;
}
}
## change to the next month
else if ($command == "next_month")
{
if (++$month == 13)
{
$month = 1;
$year++;
}
}

## if no month has been passed
if ($month == "")
{
$year= date("Y");
$month= date("n");
$month_name = date("F",mktime(0,0,0,$month,1,$year));
}
## use current date if no month is passed
else
{
$year= date("Y",mktime(0,0,0,$month,1,$year));
$month= date("n",mktime(0,0,0,$month,1,$year));
$month_name = date("F",mktime(0,0,0,$month,1,$year));
}


$dow = date("w",mktime(0,0,0,$month,1,$year)); //which day 1 falls on in the week
(0 = Sun)
$dim = date("d",mktime (0,0,0,$month+1,0,$year)); //days in the current month
## modification to only print the number of weeks in a month
$wim = ceil(($dim+$dow)/7); //weeks in month

$ct=0;

echo "<br>
<table border='0' cellpadding='1' cellspacing='1' width='425' align='center'>
<tr>
<td align='center'><h1><a href='index.php?
command=prev_month&month=$month&year=$year'><<</a> $month_name $year <a
href='index.php?command=next_month&month=$month&year=$year'>>></a></h1></td>
</tr>
</table>
<table border='1' cellpadding='1' cellspacing='1' width='425' align='center'>
<tr>
<td align='center'><b>Sun</td>
<td align='center'><b>Mon</td>
<td align='center'><b>Tue</td>
<td align='center'><b>Wed</td>
<td align='center'><b>Thu</td>
<td align='center'><b>Fri</td>
<td align='center'><b>Sat</td>
</tr>
";

## print only the number of weeks needed
for($row=1;$row<$wim+1;$row++)
{
echo "<tr height='60'>";

## prints week (Sun to Sat)
for($week=1;$week<8;$week++)
{
$ct++;
$value=mktime(0,0,0,$month,$ct-$dow,$year);

## if $value is part of current month
if (date("m",$value)==$month)
{
echo "
<td align='center' class='body' width='85' valign='top'>
<div align='right'><b>".date("j",$value)."</a></b></div><br>
</td>";
}
## print previous and next month dates, but grayed out
else
{
echo "<td align='center' class='body' width='85' valign='top'
bgcolor='#CCCCCC'><div
align='right'><b>".date("j",$value)."</a></b></div><br></td>";
}
}

echo "</tr>";
}


echo "</table>";

?>

    PHP  - Hi, the date is: Mon Jan 05, 2004 - The time is: 11:40:54 EDT
Posted By: JimmyOctane   Contact
Hi, the date is: Mon Jan 05, 2004 - The time is: 11:40:54 EDT
The above was done with:


Hi, the date is:
<?
echo date("D M d, Y", time());
?>
- The time is:
<?
echo date("H:i:s", time());
?>
EDT

The date() function is used to display times and dates in various ways. The function takes a format string and a time as arguments. If the time argument is left off, the current time and date will be used. The time argument is specified as an integer in number of seconds since the Unix Epoch on January 1, 1970. The format string is used to indicate which date/time components should be displayed and how they should be formatted.

For example, if we wanted to print the current date and time, we might use a tag like: <?echo date("D M d, Y H:i:s",time())?>. This looks like: Mon Jan 05, 2004 11:40:54

In the above you will find that the various characters in the formatting string were replaced with a date/time component. Any characters not replaced with anything were displayed verbosely. The valid formatting characters are:

Y - Year eg. 2004
y - Year eg. 04
M - Month eg. Jan
m - Month eg. 01
D - Day eg. Mon
d - Day eg. 05
z - Day of the year eg. 4
H - Hours in 24 hour format eg. 11
h - Hours in 12 hour format eg. 11
i - Minutes eg. 40
s - Seconds eg. 54
U - Seconds since epoch eg. 1073320854

    PHP  - More Includes
Posted By: Mike   Contact
<pre><br> Following up on Jamie's include example, you can define constants in something like a config.php file and use
them throughout your site/application:

config.php

------------------------------
<?php

define( "db_host", "localhost" );
define( "db_username", "username" );
define( "db_password", "password" );
define( "db_name", "username_db" );
define( "site_name", "My Site Name" );
define( "site_url", "http://www.mysitename.com/" );
define( "paypal_email", "payments@mysitename.com" );
define( "notify_email", "webmaster@mysitename.com" );
define( "registration_notifications", "yes" );

?>



examples.php
---------------------
include 'config.php';
include 'calculations.php';

// echo the site name on your page
<div align="left" class="cws_category"><? echo site_name ?></div>


// use to make MySQL connections
$db_host = db_host;
$db_username = db_username;
$db_password = db_password;
$db_name = db_name;

$connection = mysql_connect( $db_host, $db_username, $db_password ) or die( mysql_error() );
$db = mysql_SELECT_db( $db_name, $connection );

$sql = "SELECT DISTINCT * FROM registered WHERE sess_id = '$session' ORDER BY childFirst";
$result = mysql_query( $sql );

// populate hidden fields
<input type="hidden" name="business" value="<? echo paypal_email; ?>" />


// turn on/off email
if ( registration_notifications == "yes" ) {
$recipients = notify_email;
}

// switch in and out of html and php code
<td><div align="left"><strong>Father Full Name </strong>
<? if ($_POST['fatherFull']) echo $_POST['fatherFull']; ?>
</div></td>

</pre><br>

    PHP  - Simple Source Code
Posted By: Venkata Subbaiah   Contact
<pre><br> <?php
print "This is Venkata Subbaiah Bathula";

phpinfo();

?> </pre><br>

About Code400.com | resume | Search | Site Map | Suggestions
© Copyright 2003-2008 Code400.com



Thursday Sep 09, 2010 @ 9:18 PM