Archive for September 2009

Answer for question 2 in the I – BSICT Quiz

Here is the answer for question number 2 which was taken from the activity given to you.

<TABLE BORDER=”1″ CELLSPACING=0 CELLPADDING=5 RULES=”GROUPS”>

<THEAD>

<TR><TD COLSPAN=2 ROWSPAN=2></TD>

<TH COLSPAN=2 ALIGN=CENTER>Preference</TH></TR>

<TR><TH>Eating Kumquats</TH>

<TH>Poke In The Eye</TH></TR>

</THEAD>

<TBODY>

<TR ALIGN=CENTER>

<TH ROWSPAN=2>Gender</TH>

<TH>Male</TH>

<TD>73%</TD>

<TD>27%</TD></TR>

<TR ALIGN=CENTER>

<TH>Female</TH>

<TD>16%</TD>

<TD>84%</TD></TR>

</TBODY>

<TFOOT>

<TR>

<TD COLSPAN=4 ALIGN=CENTER>Note: eye pokes did not result in permanent injury</TD></TR>

</TFOOT>

<CAPTION ALIGN=BOTTOM>Kumquat versus a poked eye, by gender</CAPTION>

</TABLE>

answer no 2

answer no 2

Answer for question 1 in the I – BSICT Quiz

Here is the answer to the latest quiz for I – BSICT.

1.

for question # 1

for question # 1

<TABLE CELLPADDING=”2″ ALIGN=”center” WIDTH=”80%” border=”1″

style=”border:#000000 thin solid”>

<TR VALIGN=”top”>

<TH COLSPAN=”4″>Table Heading Cell Spanning 4 Columns</TH>

</TR>

<TR VALIGN=”top”>

<TD WIDTH=”25%”>Normal cell</TD>

<TD COLSPAN=”2″>Cell spanning 2 columns</TD>

<TD WIDTH=”25%”>Normal cell</TD>

</TR>

<TR VALIGN=”top”>

<TD ROWSPAN=”3″ BGCOLOR=”gray”>Cell spanning 3 rows with a gray (US spelling) background</TD>

<TD WIDTH=”25%”>Normal cell</TD>

<TD WIDTH=”25%”>Normal cell</TD>

<TD>Normal cell</TD>

</TR>

<TR VALIGN=”top”>

<TD>Normal cell</TD>

<TD COLSPAN=”2″ ROWSPAN=”2″>Cell spanning 2 rows and 2 columns</TD>

</TR>

<TR VALIGN=”top”>

<TD>Normal cell</TD>

</TR>

<caption align=”bottom”><b>Table Style and Formatting</b></caption>

</TABLE>

Creating a graph in PHP using PHPLOT object

Here is my example of creating a graph using an object – PHPLOT.  PHPLOT is an easy-to-use object which is now available and freeing yourself from lengthy code.  The only requirement is your knowledge in using a class, properties and methods.  The object is available is around the corner.

*********************************/
require_once(“mysqlidb.class.php”);
require_once(“config.php”);
require_once(“phplot.php”);

/* initialize connection */
$report = new mysqlidb(DB_HOST,DB_USER,DB_PWORD,DB_DATABASE);
$report->dbConnect(); //specify connection

$year = (!isset($_POST['year']))?date(“Y”):$_POST['year'];
/* retrieve result from database */
$query = “SELECT monthna,revenue FROM listofmonthlyrev WHERE ryear = $year”;
$report->viewRecord($query);

/* create an array */
$array_rep = array();
$ctr = 0;
while ($row = $report->fetchArray()){
$array_rep[$ctr] = array($row[0],$row[1]);
$ctr++;
}
/* free result */
$report->freeResult();

/* instantiate and define graph object */
$graph = new PHPlot();

/* assign data to plot */
$graph->SetImageBorderType(‘plain’);
$graph->SetPlotType(‘bars’);
$graph->SetDataType(‘text-data’);
$graph->SetDataValues($array_rep);

/* Main plot title */
$graph->SetTitle(“REVENUE FOR THE YEAR $year”);

/* Make sure Y=0 is displayed */
$graph->SetPlotAreaWorld(NULL, 0);

/* Y Tick marks are off, but Y Tick Increment also controls the Y grid lines */
$graph->SetYTickIncrement(100);

/* Turn on Y data labels */
$graph->SetYDataLabelPos(‘plotin’);

/* Turn off X tick labels and ticks because they don’t apply here: */
$graph->SetXTickLabelPos(‘none’);
$graph->SetXTickPos(‘none’);

/* With Y data labels, we don’t need Y ticks or their labels, so turn them off */
$graph->SetYTickLabelPos(‘none’);
$graph->SetYTickPos(‘none’);

/* Format the Y Data Labels as numbers with 1 decimal place. */
/* Note that this automatically calls SetYLabelType(‘data’). */
$graph->SetPrecisionY(1);

/* draw the graph */
$graph->DrawGraph();

/* close connection */
$report->disConnect();

graph using phplot

graph using phplot

Activity for I – BSICT students

Encode and save each of the html document including the embedded javascript below.  Also, study the embedded javascript for each document.  Open the document from an internet browser and draw the output in a coupon bond after clicking the click me button.  Deadline for the submission of this activity will be posted from this website or announce during the regular meeting.  Any clarification or inquiry post it by clicking the comments button below this article or message.

1.  Document number 1

<html>
<head>
<title>Javascript Number 1</title>
</head>
<body>
<input type=”button” value=”Click Me” onmousedown=”alert(‘My first javascript program.’)” />
</body>
</html>

2.  Document number 2

<html>
<head>
<title>Javascript Number 2</title>
</head>
<body>
<input type=”button” value=”Click Me”
onmousedown=”var strMessage = ‘My message using a variable.’; alert(strMessage)” />
</body>
</html>

3.  Document number 3

<html>
<head>
<title>Javascript Number 2</title>
</head>
<body>
<input type=”text” name=”txtInput” />
<input type=”button” value=”Click Me” onmousedown=”alert(txtInput.value);” />
</body>
</html>

Creating graph in PHP

The script below is a sample on how to create a bar graph using PHP language.

$arr_value = array(1 => 10, 2 => 20, 3 => 30, 4 => 40, 5 => 50);

/* image size and margin */
$img_height = 400;
$img_width = 600;
$margins = 20;

/* size of the graph – subtracting the size of borders */
$graph_width = $img_width – $margins * 2;
$graph_height = $img_height – $margins * 2;
$imageObj = imagecreate($img_width,$img_height); //create the image

/* define the width of the bar */
$bar_width = 20;
$total_bars = count($arr_value); //number of bars
//in – between spaces of the bar graph
$gap = ($graph_width – $total_bars * $bar_width)/($total_bars + 1);

/* define the colors which will be used for bars, backgrounds, lines and borders */
//int imagecollorallocate(image, int red, int green, int blue)
$bar_color = imagecolorallocate($imageObj,0,64,128);
$background_color = imagecolorallocate($imageObj,240,240,255);
$border_color = imagecolorallocate($imageObj,200,200,200);
$line_color = imagecolorallocate($imageObj,220,220,220);

/* border within the perimeter of the graph */
//bool imagefilledrectangle(image, int x1, int y1, int x2, int y2, int color)
imagefilledrectangle($imageObj,1,1,$img_width-2,$img_height-2,$border_color);
imagefilledrectangle($imageObj,$margins,$margins,$img_width-1-$margins,$img_height-1-$margins,$background_color);

/* max height of the graph */
$max_value = max($arr_value);
$ratio = $graph_height/$max_value;

/* draw horizontal lines inside the graph area */
$horizontal_lines = 20;
$horizontal_gap = $graph_height/$horizontal_lines;
for($i=1; $i<=$horizontal_lines; $i++){
$y = $img_height – $margins – $horizontal_gap * $i;
//bool imageline(image, int x1, int y1, int x2, int y2, int color
imageline($imageObj,$margins,$y,$img_width-$margins,$y,$line_color);
$v = intval($horizontal_gap * $i/$ratio);
//bool imagestring(image, int font, int x, int y, int string, int color)
imagestring($imageObj,0,5,$y-5,$v,$bar_color);
}

/* Drawing the individual bar */
for($i=0; $i<$total_bars; $i++){
list($key,$value) = each($arr_value);
$x1 = $margins + $gap + $i * ($gap + $bar_width);
$x2 = $x1 + $bar_width;
$y1 = $margins + $graph_height – intval($value * $ratio);
$y2 = $img_height – $margins;
imagefilledrectangle($imageObj,$x1,$y1,$x2,$y2,$bar_color);
imagestring($imageObj,0,$x1 + 5,$y1 – 10, $value, $bar_color);
imagestring($imageObj,0,$x1 + 3,$img_height – 15,$key,$bar_color);
}

header(“Content-type:image/png”);
imagepng($imageObj);

Output of the above PHP script.

Bar Graph

Bar Graph

Getting mac address using Javascript

Here is a sample code on how to extract the mac address of a computer using the powerful javascript.  The code will only work for internet explorer only.

<html>
<head>
<meta http-equiv=”Content-Type” content=”text/html; charset=utf-8″ />
<title>Getting MAC Address From Javascript(IE Only)</title>

<script language=”javascript”>
function showMacAddress(){

var obj = new ActiveXObject(“WbemScripting.SWbemLocator”);
var s = obj.ConnectServer(“.”);
var properties = s.ExecQuery(“SELECT * FROM Win32_NetworkAdapterConfiguration”);
var e = new Enumerator (properties);

var output;
output=’<table border=”0″ cellPadding=”5px” cellSpacing=”1px” bgColor=”#CCCCCC”>’;
output=output + ‘<tr bgColor=”#EAEAEA”><td>Caption</td><td>MACAddress</td></tr>’;
while(!e.atEnd())

{
e.moveNext();
var p = e.item ();
if(!p) continue;
output=output + ‘<tr bgColor=”#FFFFFF”>’;
output=output + ‘<td>’ + p.Caption; + ‘</td>’;
output=output + ‘<td>’ + p.MACAddress + ‘</td>’;
output=output + ‘</tr>’;
}

output=output + ‘</table>’;
document.getElementById(“box”).innerHTML=output;
}
</script>

</head>
<body>
<input type=”button” value=”Show MAC Address” onClick=”showMacAddress()” />

<div id=”box”>
</div>
</body>
</html>

Activity for I – BSICT Students (All Sections)

The activity covers the use of javascript as scripting language which will be embedded into html.  Details of the activity will posted on September 12, 2009.  Possible references can viewed or downloaded from e – Training Resources on this website.

To all BSICT students under Sir VAA

All announcements and reminders for all the subjects handled by Sir VAA can be viewed on this website.  Regular visit on this website provides updates on class discussions and deadlines on project submission which can not be announce or mention during regular meetings.  Please be reminded that late submission of projects will not be accepted.  For inquiries, you can post your message to the comments.

Online database for DMBS class is now online

Online projects for database class can now start uploading their files. Store your files on your respected directory and use user name and password which was given to you to transfer files via ftp applications.

Also, database can now be restore using the portal by following the link on DBMS Class – Online DB and use the codes which were given for every group to login. Only SQL queries can be use in restoring database.  In creating table, you have to prefix your 3 – letter code in your table name.  If you failed to include, your table might be removed from the database.

Checking of project will be on September 14, 2009 and for other announcement can be viewed on this website.

No classess on Monday (September 7, 2009)

MANILA, Philippines – President Gloria Macapagal-Arroyo declared September 7 and 21 as non-working holidays, Press Secretary Cerge Remonde said Friday night. – inquirer.net. Submission of requirements which are due on the said date will be postpone. Submission will now be on September 8, 2009 (Tuesday).