ALTER TABLE tablename AUTO_INCREMENT = 1
Tuesday, 31 May 2022
Wednesday, 11 May 2022
Prevent caching data from database in PhP FullCalendar
document.addEventListener('DOMContentLoaded', function() {
var calendarEl = document.getElementById('calendar');
var events = [];
var eventsCache = {};
var calendar = new FullCalendar.Calendar(calendarEl, {
headerToolbar: {
left: 'prev,next today',
center: 'title',
right: 'dayGridMonth,timeGridWeek,timeGridDay,listWeek'
},
eventSources: [{
cache: false,
url: 'loadevent.php',
type: 'POST',
extraParams: function() { // Prevent caching data from database in fullcalendar
return {
cachebuster: new Date().valueOf()
};
},
}],
});
calendar.render();
calendar.refetchEvents();
});
</script>
Friday, 6 May 2022
How to configure PHP Calendar with events from database?
Download fullcalendar file from : https://github.com/
<link href='fullcalendar-5.10.2/lib/
<script src='fullcalendar-5.10.2/lib/
document.addEventListener('
var calendarEl = document.getElementById('
var calendar = new FullCalendar.Calendar(
headerToolbar: {
left: 'prev,next today',
center: 'title',
right: 'dayGridMonth,timeGridWeek,
},
events: 'loadevent.php',
},
displayEventTime: false,
selectHelper:true,
weekNumbers: true,
navLinks: true, // can click day/week names to navigate views
nowIndicator: true,
weekNumbers: true,
dayMaxEventRows: true, // for all non-TimeGrid views
views: {
timeGrid: {
dayMaxEventRows: 6 // adjust to 6 only for timeGridWeek/timeGridDay
}
},
});
calendar.render();
});
</script>
<div class="container">
<div class="row">
<div class="col-md-12">
<h1 align="center" style=" padding: 3%;"> Calendar Heading</h1>
<div id='calendar'></div>
</div>
</div>
</div>
</body>
$stmt = $con->prepare(" SQL QUERY ");
$stmt->execute();
$result = $stmt->get_result();
while ($row = $result->fetch_assoc()) {
$data[] = array(
'id' => $row["No"],
'title' => $row["title"], // DB ATTRIBUTE NAME FOR TITLE
'end' => $row["DATE2"], // DB END DATE ENTRY in yy-mm-dd 00:00:00 format
'description' => $row[" Description "], // DB Description attribute
);
//result is in row
}
echo json_encode($data);
Tuesday, 3 May 2022
Warning: mysqli_query() expects parameter 1 to be mysqli, resource given
You are mixing mysqli and mysql extensions in the code, which will not work. mysqli has many improvements over the original mysql extension, so it is recommended to use mysqli .
Friday, 29 April 2022
Pre Populate jquery Token input textbox with PhP MySQLi Resultset
- Download jquery token input plugin from https://loopj.com/jquery-tokeninput/
- Extract the zip file and put jquery.tokeninput.js and token-input.css in the application root folder.
- Download the latest version of jquery.min.js
Monday, 25 April 2022
Export mysqli resultset as excel with nested table in PhP
error_reporting(E_ERROR | E_WARNING | E_PARSE);
$con = mysqli_connect("localhost", "root", "", "tablename");
if (mysqli_connect_errno()) {
echo "Failed to connect to MySQL: " . mysqli_connect_error();
}
$output = '';
$stmt3 = $con->prepare("SELECT id,registrationid,name,email,mobile,nationality,state,district,gender from adv33");
$stmt3->execute();
$stmt3->bind_result($id, $registrationid, $name, $email, $mobile, $nationality, $state, $district, $gender);
$stmt3->store_result();
if ($stmt3->num_rows > 0) {
$output .= '
<table border="1">
<tr>
<th>Name</th>
<th>Email</th>
<th>Mobile</th>
<th>Nationality</th>
<th>State</th>
<th>District</th>
<th>Gender</th>
</tr>
';
while ($stmt3->fetch()) {
$output .= '
<tr>
<td>' . $name . '</td>
<td>' . $email . '</td>
<td>' . $mobile . '</td>
<td>' . $nationality . '</td>
<td>' . $state . '</td>
<td>' . $district . '</td>
<td>' . $gender . '</td>
</tr>';
$output .= '
<table border="1">
<tr>
<td><b>Post</b></td>
<td><b>Company</b></td>
<td><b>From Date</b></td>
<td><b>To Date</b></td>
<td><b>Scale of Pay</b></td>
';
$stmt4 = $con->prepare("SELECT slno,email,post,company,fromdate,todate,scale FROM adv33exp where email ='$registrationid'");
$stmt4->execute();
/* bind result variables */
$stmt4->bind_result($slno, $email, $post, $company, $fromdate, $todate, $scale);
$stmt4->store_result();
if ($stmt4->num_rows > 0) {
/* fetch value */
while ($stmt4->fetch()) {
$output .= '
<tr>
<td>' . $post . '</td>
<td>' . $company . '</td>
<td>' . $fromdate . '</td>
<td>' . $todate . '</td>
<td>' . $scale . '</td>
</tr>
';
}
}
}
$output .= '</table>';
header("Content-type: application/octet-stream");
header("Content-Disposition: attachment; filename=Applicants.xls");
header("Pragma: no-cache");
header("Expires: 0");
echo $output;
}
?>
Friday, 22 April 2022
Add dynamic rows in html table with Add, Edit, Delete feature in PHP and MySQLi
dynamic-table.php
action.php
Config.php
class dbConfig {
protected $serverName;
protected $userName;
protected $password;
protected $dbName;
function dbConfig() {
$this -> serverName = 'localhost';
$this -> userName = 'root';
$this -> password = "";
$this -> dbName = "employee";
}
}
?>
Employee.php
<?php require('config.php'); class Employee extends Dbconfig { protected $hostName; protected $userName; protected $password; protected $dbName; private $empTable = 'employment'; private $dbConnect = false; public function __construct(){ if(!$this->dbConnect){ $database = new dbConfig(); $this -> hostName = $database -> serverName; $this -> userName = $database -> userName; $this -> password = $database ->password; $this -> dbName = $database -> dbName; $conn = new mysqli($this->hostName, $this->userName, $this->password, $this->dbName); if($conn->connect_error){ die("Error failed to connect to MySQL: " . $conn->connect_error); } else{ $this->dbConnect = $conn; } } } public function employeeList(){ $sqlQuery = "SELECT * FROM ".$this->empTable." "; $result = mysqli_query($this->dbConnect, $sqlQuery); $employeeData = array(); while( $employee = mysqli_fetch_assoc($result) ) { $empRows = array(); $empRows[] = $employee['post']; $empRows[] = $employee['company']; $empRows[] = $employee['type']; $empRows[] = $employee['fromdate']; $empRows[] = $employee['todate']; $empRows[] = $employee['scale']; $empRows[] = $employee['gross']; $empRows[] = '<button type="button" name="update" id="'.$employee["id"].'" class="btn btn-warning btn-xs update">Update</button>'; $empRows[] = '<button type="button" name="delete" id="'.$employee["id"].'" class="btn btn-danger btn-xs delete" >Delete</button>'; $employeeData[] = $empRows; } $output = array( "draw" => intval($_POST["draw"]), "data" => $employeeData ); echo json_encode($output); } public function getEmployee(){ if($_POST["empId"]) { $sqlQuery = " SELECT * FROM ".$this->empTable." WHERE id = '".$_POST["empId"]."'"; $result = mysqli_query($this->dbConnect, $sqlQuery); $row = mysqli_fetch_array($result, MYSQLI_ASSOC); echo json_encode($row); } } public function updateEmployee(){ if($_POST['empId']) { $updateQuery = "UPDATE ".$this->empTable." SET userid = '".$_POST["userid"]."', post = '".$_POST["post"]."', company = '".$_POST["company"]."', type = '".$_POST["type"]."', fromdate = '".$_POST["fromdate"]."' , todate = '".$_POST["todate"]."' , scale = '".$_POST["scale"]."', gross = '".$_POST["gross"]."' WHERE id ='".$_POST["empId"]."'"; $isUpdated = mysqli_query($this->dbConnect, $updateQuery); } } public function addEmployee(){ $insertQuery = "INSERT INTO ".$this->empTable." (userid, post, company, type, fromdate, todate,scale, gross) VALUES ('".$_POST["userid"]."','".$_POST["post"]."', '".$_POST["company"]."', '".$_POST["type"]."', '".$_POST["fromdate"]."', '".$_POST["todate"]."', '".$_POST["scale"]."', '".$_POST["gross"]."')"; $isUpdated = mysqli_query($this->dbConnect, $insertQuery); } public function deleteEmployee(){ if($_POST["empId"]) { $sqlDelete = " DELETE FROM ".$this->empTable." WHERE id = '".$_POST["empId"]."'"; mysqli_query($this->dbConnect, $sqlDelete); } } } ?>
employee.sql