Insert google map in your website php code
<style>
#contact-map {
height: 500px;
}
</style>
<div id="contact-map"></div>
<script>
var map;
function initMap() {
var myLatlng = new google.maps.LatLng(your lat,your lng);
map = new google.maps.Map(document.getElementById('contact-map'), {
center: myLatlng,
zoom: 15
});
var marker = new google.maps.Marker({
position: myLatlng,
title:"TITLE "
});
marker.setMap(map);
}
</script>
<script src="https://maps.googleapis.com/maps/api/js?key=AIzaSyB5O1LcvjU5OnLyfwTr2dmo9zu_1zql_UQ&callback=initMap"
async defer></script>
#contact-map {
height: 500px;
}
</style>
<div id="contact-map"></div>
<script>
var map;
function initMap() {
var myLatlng = new google.maps.LatLng(your lat,your lng);
map = new google.maps.Map(document.getElementById('contact-map'), {
center: myLatlng,
zoom: 15
});
var marker = new google.maps.Marker({
position: myLatlng,
title:"TITLE "
});
marker.setMap(map);
}
</script>
<script src="https://maps.googleapis.com/maps/api/js?key=AIzaSyB5O1LcvjU5OnLyfwTr2dmo9zu_1zql_UQ&callback=initMap"
async defer></script>
ADD random new article in joomla through php code
instruction
1) create a new php file add code give below.
2) put this file in joomla folder of your project.
3) run this php file.
////////////////////////////////code////////////////////////////////////
<!DOCTYPE html>
<html>
<head>
<title></title>
</head>
<body>
<div id="progress" style="width:500px;border:1px solid #ccc;"></div>
<!-- Progress information -->
<div id="information" style="width"></div>
</body>
</html>
<?php
define('_JEXEC', 1);
define('DS', DIRECTORY_SEPARATOR);
if (file_exists(dirname(__FILE__) . '/defines.php')) {
include_once dirname(__FILE__) . '/defines.php';
}
if (!defined('_JDEFINES')) {
define('JPATH_BASE', dirname(__FILE__));
require_once JPATH_BASE.'/includes/defines.php';
}
//define('JPATH_COMPONENT_ADMINISTRATOR', dirname(__FILE__) . "/administrator");
define('JPATH_COMPONENT_ADMINISTRATOR', JPATH_BASE . DS . 'administrator' . DS . 'components' . DS . 'com_content');
require_once JPATH_BASE.'/includes/framework.php';
//$app = JFactory::getApplication('site');
//require_once JPATH_BASE.'/includes/framework.php';
//echo JPATH_BASE. "/administrator/components/com_content/models/article.php";
require_once JPATH_BASE. "/administrator/components/com_content/models/article.php";
//administrator/components/com_content/models
$app = JFactory::getApplication('site', array('session' => false));
$total=100;
for($i=0;$i<100;$i++){
$title_script="title".$i;
$main_discription="Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod";
$data = array(
'catid' => 80, //newsarticles
'title' => $title_script,
'introtext' =>$main_discription,
'fulltext' => '',
'state' => 1,);
$title_script="";
$main_discription="";
$new_article = new ContentModelArticle();
//print_r($data);
$new_article->save($data);
// add progress bar
$percent = intval($i/$total * 100)."%";
echo '<script language="javascript">
document.getElementById("progress").innerHTML="<div style=\"width:'.$percent.';background-color:#ddd;\"> </div>";
document.getElementById("information").innerHTML="'.$i.' row(s) processed.";
</script>';
// This is for the buffer achieve the minimum size in order to flush data
echo str_repeat(' ',1024*64);
// Send output to browser immediately
flush();
// Sleep one second so we can see the delay
sleep(1);
echo '<script language="javascript">document.getElementById("information").innerHTML="Process completed"</script>';
}
?>
////////////////////////////////////////////////////////////////////////////////
1) create a new php file add code give below.
2) put this file in joomla folder of your project.
3) run this php file.
////////////////////////////////code////////////////////////////////////
<!DOCTYPE html>
<html>
<head>
<title></title>
</head>
<body>
<div id="progress" style="width:500px;border:1px solid #ccc;"></div>
<!-- Progress information -->
<div id="information" style="width"></div>
</body>
</html>
<?php
define('_JEXEC', 1);
define('DS', DIRECTORY_SEPARATOR);
if (file_exists(dirname(__FILE__) . '/defines.php')) {
include_once dirname(__FILE__) . '/defines.php';
}
if (!defined('_JDEFINES')) {
define('JPATH_BASE', dirname(__FILE__));
require_once JPATH_BASE.'/includes/defines.php';
}
//define('JPATH_COMPONENT_ADMINISTRATOR', dirname(__FILE__) . "/administrator");
define('JPATH_COMPONENT_ADMINISTRATOR', JPATH_BASE . DS . 'administrator' . DS . 'components' . DS . 'com_content');
require_once JPATH_BASE.'/includes/framework.php';
//$app = JFactory::getApplication('site');
//require_once JPATH_BASE.'/includes/framework.php';
//echo JPATH_BASE. "/administrator/components/com_content/models/article.php";
require_once JPATH_BASE. "/administrator/components/com_content/models/article.php";
//administrator/components/com_content/models
$app = JFactory::getApplication('site', array('session' => false));
$total=100;
for($i=0;$i<100;$i++){
$title_script="title".$i;
$main_discription="Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod";
$data = array(
'catid' => 80, //newsarticles
'title' => $title_script,
'introtext' =>$main_discription,
'fulltext' => '',
'state' => 1,);
$title_script="";
$main_discription="";
$new_article = new ContentModelArticle();
//print_r($data);
$new_article->save($data);
// add progress bar
$percent = intval($i/$total * 100)."%";
echo '<script language="javascript">
document.getElementById("progress").innerHTML="<div style=\"width:'.$percent.';background-color:#ddd;\"> </div>";
document.getElementById("information").innerHTML="'.$i.' row(s) processed.";
</script>';
// This is for the buffer achieve the minimum size in order to flush data
echo str_repeat(' ',1024*64);
// Send output to browser immediately
flush();
// Sleep one second so we can see the delay
sleep(1);
echo '<script language="javascript">document.getElementById("information").innerHTML="Process completed"</script>';
}
?>
////////////////////////////////////////////////////////////////////////////////
progress bar through php
<!DOCTYPE html>
<html>
<head>
<title></title>
</head>
<body>
<div id="progress" style="width:500px;border:1px solid #ccc;"></div>
<!-- Progress information -->
<div id="information" style="width"></div>
</body>
</html>
<?php
$total=50;
for($i=0;$i<$total;$i++){
$percent = intval($i/$total * 100)."%";
echo '<script language="javascript">
document.getElementById("progress").innerHTML="<div style=\"width:'.$percent.';background-color:orange;\"> </div>";
document.getElementById("information").innerHTML="'.$i.' row(s) processed.";
</script>';
// This is for the buffer achieve the minimum size in order to flush data
echo str_repeat(' ',1024*64);
// Send output to browser immediately
flush();
// Sleep one second so we can see the delay
sleep(1);
echo '<script language="javascript">document.getElementById("information").innerHTML="Process completed"</script>';
}
?>
<html>
<head>
<title></title>
</head>
<body>
<div id="progress" style="width:500px;border:1px solid #ccc;"></div>
<!-- Progress information -->
<div id="information" style="width"></div>
</body>
</html>
<?php
$total=50;
for($i=0;$i<$total;$i++){
$percent = intval($i/$total * 100)."%";
echo '<script language="javascript">
document.getElementById("progress").innerHTML="<div style=\"width:'.$percent.';background-color:orange;\"> </div>";
document.getElementById("information").innerHTML="'.$i.' row(s) processed.";
</script>';
// This is for the buffer achieve the minimum size in order to flush data
echo str_repeat(' ',1024*64);
// Send output to browser immediately
flush();
// Sleep one second so we can see the delay
sleep(1);
echo '<script language="javascript">document.getElementById("information").innerHTML="Process completed"</script>';
}
?>
How to make CSV file from mysql database using PHP
This example demonstrate how to make csv file form mysql table using php. in this example csv file will contain name, username and email from user table. database connection has been takem dynamically from joomla configuration.php file. you need to change it as your requirement.
<?php
require_once "configuration.php";
$config = new JConfig();
$host = $config->host;
$db = $config->db;
$dbprefix = $config->dbprefix;
$password = $config->password;
$user = $config->user;
$con = new mysqli($host,$user,$password, $db);
$filename = "users.csv";
$fp = fopen('php://output', 'w');
$header = array("name","username","email");
header('Content-type: application/csv');
header('Content-Disposition: attachment; filename='.$filename);
fputcsv($fp, $header);
$query = "SELECT name, username, email FROM jnr6o_users";
$result = $con->query($query);
while($row = mysqli_fetch_row($result)) {
fputcsv($fp, $row);
}
exit;
?>
<?php
require_once "configuration.php";
$config = new JConfig();
$host = $config->host;
$db = $config->db;
$dbprefix = $config->dbprefix;
$password = $config->password;
$user = $config->user;
$con = new mysqli($host,$user,$password, $db);
$filename = "users.csv";
$fp = fopen('php://output', 'w');
$header = array("name","username","email");
header('Content-type: application/csv');
header('Content-Disposition: attachment; filename='.$filename);
fputcsv($fp, $header);
$query = "SELECT name, username, email FROM jnr6o_users";
$result = $con->query($query);
while($row = mysqli_fetch_row($result)) {
fputcsv($fp, $row);
}
exit;
?>
How to configure mysql connection dynamically in joomla website.
How to configure core php-mysql connection dynamically in joomla website form configuration file.
<?php
require_once "../configuration.php";
$config = new JConfig();
$host = $config->host;
$db = $config->db;
$dbprefix = $config->dbprefix;
$password = $config->password;
$user = $config->user;
$con = new mysqli($host,$user,$password, $db);
if ($con->connect_error) {
die("Connection failed: " . $con->connect_error);
}
?>
<?php
require_once "../configuration.php";
$config = new JConfig();
$host = $config->host;
$db = $config->db;
$dbprefix = $config->dbprefix;
$password = $config->password;
$user = $config->user;
$con = new mysqli($host,$user,$password, $db);
if ($con->connect_error) {
die("Connection failed: " . $con->connect_error);
}
?>
Import data from CSV file to mysql database using PHP
<?php
$host = "localhost"
$user = username;
$password = database password;
$db =database name;
$con = new mysqli($host,$user,$password, $db);
if ($con->connect_error) {
die("Connection failed: " . $con->connect_error);
}
?>
<html>
<head>
<style type='text/css'>
body
{
margin: 0;
padding: 0;
background-color:#FFFFFF;
text-align:center;
}
.top-bar
{
width: 100%;
height: auto;
text-align: center;
background-color:#FFF;
border-bottom: 1px solid #000;
margin-bottom: 20px;
}
.inside-top-bar
{
margin-top: 5px;
margin-bottom: 5px;
}
.link
{
font-size: 18px;
text-decoration: none;
background-color: #000;
color: #FFF;
padding: 5px;
}
.link:hover
{
background-color: #FCF3F3;
}
</style>
</head>
<body>
<div class='top-bar'>
<div class='inside-top-bar'>Import CSV file to mysql table <br><br>
</div>
</div>
<div style='text-align:left; border:1px solid #333333; width:300px; margin:0 auto; padding:10px;'>
<form name='import' method='post' enctype='multipart/form-data'>
<input type='file' name='file' /><br />
<input type='submit' name='submit' value='Submit' />
</form>
<?php
if(isset($_POST['submit']))
{
$file = $_FILES['file']['tmp_name'];
$fetch = $con->query("SELECT username FROM tablename"); //tablename in which you import the data
$i=0;
while($fetch_array = mysqli_fetch_array($fetch)){ //checks if the record already exist or not. if exist it skips
$variablename[$i++]=$fetch_array["columnname"]; // columnname in column which is unique
}
$handle = fopen($file, 'r');
$c = 0;
while(($filesop = fgetcsv($handle, 1000, ',')) !== false)
{
if($filesop[0]=="columnname in csv" || $filesop[0]=="" || in_array(fieldname,array of table))
continue;
///////////////////////////////////// just for reference
$name = $filesop[1];
$username = $filesop[3];
$email = $filesop[2];
$password = $filesop[4];
$password = md5($password);
$created_on = $filesop[0];
/////////////////////////////////////// values as above variables
$sql = $con->query("INSERT INTO table name (columnnames) VALUES ('"values");
$c = $c + 1;
}
if($c){
echo "You database has imported successfully. You have inserted ". $c ." records";
}else{
echo "no record inserted.";
}
}
?>
</div>
</body>
</html>
Find age thought php code
This is one of the simple task in php.
<?php
$birthdate='1989-07-07';
echo date_diff(date_create($birthdate), date_create('today'))->y;
?>
Subscribe to:
Posts
(
Atom
)