HOME BLOG PORTFOLIO PHOTO CONTACT Admin Login
bar format in php

This php, javascrip, ajax code responsible for display student result in a graphical/bar chart format:

for try click here

Below php code just copy paste and run it.

< ?php
class marks
{
public function marks()
{
}
private static function databaseVariables()
{
//static $host="localhost";
static $host="127.0.0.1";
static $user="root";
static $password="";
static $db="marks";
return ($host."/".$user."/".$password."/".$db);
}
public function dbConnect()
{
$temp = explode('/',marks::databaseVariables());
$db1 = @mysqli_connect($temp[0],$temp[1],$temp[2],$temp[3])or die ('Oops! There was a problem connecting to the Database Server.'. mysql_error());
return $db1;
}
public static function getMarks($db1)
{
$qry1 = "SELECT name,id,marks FROM examfinalip WHERE 1 ORDER BY id DESC";
$result1 = @mysqli_query ($db1, $qry1)or die ('Oops! There was a problem connecting to the Database Server or no query found.');
$marks_array1=array();
while ($row1 = mysqli_fetch_assoc($result1))
{
array_push($marks_array1,$row1);
}
// Free memory
mysqli_free_result($result1);
return $marks_array1;
}
public static function addMarks($db1, $name, $marks)
{
$name = marks::mysqlInjectionFilter($db1, $name);
$marks = marks::mysqlInjectionFilter($db1, $marks);
if($checkAvalibility = marks::CheckAvalibility($db1, "SELECT * FROM examfinalip WHERE name='".$name."'"))
{
$ip = $_SERVER['REMOTE_ADDR'];
$visit_time = time();
//$currentDate = date("m d y", time());
$currentDate = mktime(0, 0, 0, date(m), date(d), date(y));
if($checkIPDate = marks::checkIPDate($db1, $ip, $visit_time))
{
//true
return "checkIPDate";
//return "Sorry, No permission multi Records Saving , Please change your ip connection or change your date greater then today";
//return "checkIPDate";
}
else
{
//false 0
//echo "ADDING";
if($result = marks::executeQuery($db1, "INSERT INTO examfinalip SET name='".$name."', marks='".$marks."', ip='".$ip."', visit_time='".$visit_time."' "))
{
return "Congrates, Records Saving Success";
}
else
{
return "Failure Record Not Saving executeQuery";;
}
}
}
else
{
//echo "Record Allready Stored";
//return "Record Allready Stored";;
return "CheckAvalibility";
}

//$qry1 = "INSERT INTO examfinalip SET name='".$name."', marks='".$marks."' ";

}
private static function mysqlInjectionFilter($db1, $val)
{
return (mysqli_real_escape_string($db1,$val));
}
private static function CheckAvalibility($db1, $sql)
{
//echo $sql;
$result1 = @mysqli_query ($db1, $sql)or die ('Oops! There was a problem connecting to the Database Server or no query found.');
$num = mysqli_num_rows($result1);
if($num)
{
return FALSE;
}
else
{
return TRUE;
}
}
private static function checkIPDate($db1, $ip, $visit_time)
{
$currentDate = mktime(0, 0, 0, date(m), date(d), date(y));
$qry1 = "SELECT * FROM examfinalip WHERE ( (ip = '".$ip."') AND ( visit_time > ‘”.$currentDate.”‘) ) “;
$result1 = @mysqli_query ($db1, $qry1)or die (‘Oops! Error checkIPDate There was a problem connecting to the Database Server or no query found.’);
$num = mysqli_num_rows($result1);
$row1=mysqli_fetch_array($result1);
if($num)
{
return TRUE;
}
else
{
return FALSE;
}
}
private static function executeQuery($db1, $sql)
{
$result1 = @mysqli_query ($db1, $sql)or die (‘Oops! executeQuery There was a problem connecting to the Database Server or no query found.’);
if($result1)
{
return TRUE;
}
else
{
return FALSE;
}
}
// this is destructor
function __destruct()
{
//echo “jay called this automatic in end”;
// Free memory
}
}
?>
< ?php
ob_start();
$marks1 = new marks();
$db1 = $marks1->dbConnect();
$marks_array1=$marks1->getMarks($db1);

if($_POST['submit1']==”save”)
{
$result = $marks1->addMarks($db1, $_POST['name'], $_POST['marks']);
//echo $result;
if($result == “checkIPDate”)
{
$checkIPDateError = “Sorry in a day with this IP address only one entry permitted.
For more entry change your date setting to the next day”;
}
elseif($result == “CheckAvalibility”)
{
$CheckAvalibilityError = “Sorry this name Record Allready Stored”;
}
$marks1 = new marks();
$db1 = $marks1->dbConnect();
$marks_array1=$marks1->getMarks($db1);
unset($_POST['name'],$_POST['marks']);
}
//print_r($_POST);
?>
< !DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">

 

 

This code demostrate to display student marks in graphical format (bar chart), jay bharat

< ?php
if(($checkIPDateError) || ($CheckAvalibilityError))
{
?>

< ?php echo $checkIPDateError.$CheckAvalibilityError; ?>

< ?php
}
?>

ADD MARKS
 
< ?php
foreach($marks_array1 as $key=>$temp1)
{
?>
< ?php echo "&amp;amp;amp;amp;amp;nbsp;".$temp1['marks']."%"; ?>

< ?php
}
?>



< ?php
ob_flush();
unset($marks_array1, $temp1, $db1);
?>

 

Below mysql databse.

 

– phpMyAdmin SQL Dump
– version 2.10.1
– http://www.phpmyadmin.net

– Host: localhost
– Generation Time: Mar 04, 2009 at 05:48 PM
– Server version: 5.0.45
– PHP Version: 5.2.5

SET SQL_MODE=”NO_AUTO_VALUE_ON_ZERO”;


– Database: `marks`

– ——————————————————–


– Table structure for table `examfinalip`

CREATE TABLE `examfinalip` (
`id` int(2) NOT NULL auto_increment,
`name` varchar(255) NOT NULL,
`marks` int(2) NOT NULL,
`ip` varchar(32) NOT NULL,
`visit_time` int(20) NOT NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1 AUTO_INCREMENT=2 ;


– Dumping data for table `examfinalip`

INSERT INTO `examfinalip` (`id`, `name`, `marks`, `ip`, `visit_time`) VALUES
(1, ‘david’, 88, ’127.0.0.1′, 1236003110);
 

   Share on Facebook

Page views:412