It is all about programming. A blog about PHP, MYSQL, Javascript, Jquery,AJAX,HTML & CSS tutorial. Get short trick, knowledge based snippet for programming and technology related ideas.
Showing posts with label PHP and MySQL. Show all posts
Showing posts with label PHP and MySQL. Show all posts
Wednesday, 2 March 2016
How datetime column of database auto fill with current date and time
Wednesday, 6 January 2016
Opencart checkout page is not working
Opencart checkout page is not working mean content is not loading using AJAX within first tab.
Reason : Javascript conflict or error in syntax but generally due to conflict.
Solution : Just remove all external JS file or comment it one by one and check which javascript is conflicting.
You will get that comment it or use on Jquery no conflict code
Reason : Javascript conflict or error in syntax but generally due to conflict.
Solution : Just remove all external JS file or comment it one by one and check which javascript is conflicting.
You will get that comment it or use on Jquery no conflict code
Sunday, 9 August 2015
How to Join more than two table in MySQL
Join two or more table in MySQL. Very easy steps to joining more than two table.
Here, table name = student,exam and grade.
Joining query on three table with common matching column. See below
SELECT *
from
tableA
inner join
tableB
ON tableA.common = tableB.common
inner join
TableC
ON TableB.common = TableC.common
Here, table name = student,exam and grade.
Joining query on three table with common matching column. See below
SELECT *
from
tableA
inner join
tableB
ON tableA.common = tableB.common
inner join
TableC
ON TableB.common = TableC.common
Friday, 14 November 2014
Pagination within a div
Pagination within a div
Step 1: HTML
<link rel="stylesheet" href="css/main.css" type="text/css" />
<script src="js/jquery.min.js"></script>
<script src="js/pager.js"></script>
<div class="example">
<h3><a href="#">pagination sample</a></h3>
<div id="content">
<?php
$sql="select * from `tablename`";
if($dd=mysql_query($sql))
{
while($DD=mysql_fetch_array($dd))
{ ?>
<div class="z"><?php echo $DD['name']; ?> </div>
<?php }?>
<div id="content">
<?php
$sql="select * from `tablename`";
if($dd=mysql_query($sql))
{
while($DD=mysql_fetch_array($dd))
{ ?>
<div class="z"><?php echo $DD['name']; ?> </div>
<?php }?>
</div>
<div id="pagingControls"></div>
</div>
<script type="text/javascript">
var pager = new Imtech.Pager();
$(document).ready(function() {
pager.paragraphsPerPage = 5; // set amount elements per page
pager.pagingContainer = $('#content'); // set of main container
pager.paragraphs = $('div.z', pager.pagingContainer); // set of required containers
pager.showPage(1);
});
</script>
STEP 2: CSS
css/main.css
body{background:#eee;font-family:Verdana, Helvetica, Arial, sans-serif;margin:0;padding:0}
.example{background:#FFF;width:1000px;font-size:80%;border:1px #000 solid;margin:0.5em 10% 0.5em;padding:1em 2em 2em;-moz-border-radius:3px;-webkit-border-radius:3px}
#content p{text-indent:20px;text-align:justify;}
#pagingControls ul{display:inline;padding-left:0.5em}
#pagingControls li{display:inline;padding:0 0.5em}
STEP 3: JS
js/jquery.min.js ( – just jQuery library. Available in package.)
js/pager.js
var Imtech = {};
Imtech.Pager = function() {
this.paragraphsPerPage = 3;
this.currentPage = 1;
this.pagingControlsContainer = '#pagingControls';
this.pagingContainerPath = '#content';
this.numPages = function() {
var numPages = 0;
if (this.paragraphs != null && this.paragraphsPerPage != null) {
numPages = Math.ceil(this.paragraphs.length / this.paragraphsPerPage);
}
return numPages;
};
this.showPage = function(page) {
this.currentPage = page;
var html = '';
this.paragraphs.slice((page-1) * this.paragraphsPerPage,
((page-1)*this.paragraphsPerPage) + this.paragraphsPerPage).each(function() {
html += '<div>' + $(this).html() + '</div>';
});
$(this.pagingContainerPath).html(html);
renderControls(this.pagingControlsContainer, this.currentPage, this.numPages());
}
var renderControls = function(container, currentPage, numPages) {
var pagingControls = 'Page: <ul>';
for (var i = 1; i <= numPages; i++) {
if (i != currentPage) {
pagingControls += '<li><a href="#" onclick="pager.showPage(' + i + '); return false;">' + i + '</a></li>';
} else {
pagingControls += '<li>' + i + '</li>';
}
}
pagingControls += '</ul>';
$(container).html(pagingControls);
}
}
Wednesday, 29 October 2014
two different query to assign in a single variable to fetch data
<?php
$query = sprintf("SELECT * FROM `registered_profile` WHERE (`industry`='". $_POST['industry']."' && `subindustry`='".$_POST['subindustry']."' && `city`='".$_POST['city']."' && `status`='Y') || `subindustry`='".$_GET['id']."' || `state`='".$_GET['id1']."' || `city`='".$_GET['id2']."'");
if(isset($_POST['search']))
{
$query = sprintf("SELECT * FROM `registered_profile` WHERE `company_address` REGEXP '" . mysql_real_escape_string($_POST['search']) . "'");
}
$row = mysql_query($query);
?>
$query = sprintf("SELECT * FROM `registered_profile` WHERE (`industry`='". $_POST['industry']."' && `subindustry`='".$_POST['subindustry']."' && `city`='".$_POST['city']."' && `status`='Y') || `subindustry`='".$_GET['id']."' || `state`='".$_GET['id1']."' || `city`='".$_GET['id2']."'");
if(isset($_POST['search']))
{
$query = sprintf("SELECT * FROM `registered_profile` WHERE `company_address` REGEXP '" . mysql_real_escape_string($_POST['search']) . "'");
}
$row = mysql_query($query);
?>
Tuesday, 7 October 2014
to go to another page from a link of pop div
use this syntax:--
<a href="name of page with extension" onclick="open()" >vikash</a>
///simply call an open method on onclick of a link
<a href="name of page with extension" onclick="open()" >vikash</a>
///simply call an open method on onclick of a link
Tuesday, 16 September 2014
php code to save a mysql query into an array
$data = array();
while ($row = mysql_fetch_array($myVariable)) {
$data[] = $row;
}
//now $data has all the rows. a simple foreach will loop over the data.
foreach($data as $row){
//do events
print_r($row);
}
//and you can loop over data again and again.
foreach($data as $row){
//do events
print_r($row);
}
while ($row = mysql_fetch_array($myVariable)) {
$data[] = $row;
}
//now $data has all the rows. a simple foreach will loop over the data.
foreach($data as $row){
//do events
print_r($row);
}
//and you can loop over data again and again.
foreach($data as $row){
//do events
print_r($row);
}
PHP Connect to the MySQL Server
mysqli_connect(host,username,password,dbname);
upload an image and view it using php
save as img.php to get a form of upload
<form action="saveimage.php" enctype="multipart/form-data" method="post">
<table style="border-collapse: collapse; font: 12px Tahoma;" border="1" cellspacing="5" cellpadding="5">
<tbody><tr>
<td>
<input name="uploadedimage" type="file">
</td>
</tr>
<tr>
<td>
<input name="Upload Now" type="submit" value="Upload Image">
</td>
</tr>
</tbody></table>
</form>
Save as saveimage.php
<?php
/**********MYSQL Settings****************/
$host="localhost";
$databasename="image";
$user="root";
$pass="";
/**********MYSQL Settings****************/
$conn=mysql_connect($host,$user,$pass);
if($conn)
{
$db_selected = mysql_select_db($databasename, $conn);
if (!$db_selected) {
die ('Can\'t use foo : ' . mysql_error());
}
}
else
{
die('Not connected : ' . mysql_error());
}
?>
<?php /*
function GetImageExtension($imagetype)
{
if(empty($imagetype)) return false;
switch($imagetype)
{
case 'image/bmp': return '.bmp';
case 'image/gif': return '.gif';
case 'image/jpeg': return '.jpg';
case 'image/png': return '.png';
default: return false;
}
} */
?>
<?php
error_reporting(0);
//include("mysqlconnect.php");
function GetImageExtension($imagetype)
{ if(empty($imagetype)) return false;
switch($imagetype)
{
case 'image/bmp': return '.bmp';
case 'image/gif': return '.gif';
case 'image/jpeg': return '.jpg';
case 'image/png': return '.png';
default: return false;
}
}
if (!empty($_FILES["uploadedimage"]["name"])) {
$file_name=$_FILES["uploadedimage"]["name"];
$temp_name=$_FILES["uploadedimage"]["tmp_name"];
$imgtype=$_FILES["uploadedimage"]["type"];
$ext= GetImageExtension($imgtype);
$imagename=date("d-m-Y")."-".time().$ext;
$target_path = "C:/wamp/www/imagefetch/IMAGE/".$imagename;
if(move_uploaded_file($temp_name, $target_path)) {
$query_upload="INSERT INTO `images_tbl`(`images_path`,`submission_date`) VALUES
('".$target_path."','".date("Y-m-d")."')";
mysql_query($query_upload) or die("error in $query_upload == ----> ".mysql_error());
echo "uploaded successfully";
}else{
exit("Error While uploading image on the server");
}
}
?>
<?php
///Code to use image name with new customized image name .
$imagename=date("d-m-Y")."-".time().$ext;
///Code to use image name as same as uploaded image name .
$imagename=$_FILES["uploadedimage"]["name"];
?>
Save as view.php to view image
<?php
/**********MYSQL Settings****************/
$host="localhost";
$databasename="image";
$user="root";
$pass="";
/**********MYSQL Settings****************/
$conn=mysql_connect($host,$user,$pass);
if($conn)
{
$db_selected = mysql_select_db($databasename, $conn);
if (!$db_selected) {
die ('Can\'t use foo : ' . mysql_error());
}
}
else
{
die('Not connected : ' . mysql_error());
}
?>
<?php
//include("mysqlconnect.php");
$select_query = "SELECT `images_path` FROM `images_tbl` ORDER BY `images_id` DESC";
$sql = mysql_query($select_query) or die(mysql_error());
while($row = mysql_fetch_array($sql)){
?>
<table style="border-collapse: collapse; font: 12px Tahoma;" border="1" cellpadding="5" cellspacing="5">
<tbody><tr>
<td>
<img src="<?=$row['images_path`']?>">
</td>
</tr>
</tbody></table>
<?php
}
?>
<form action="saveimage.php" enctype="multipart/form-data" method="post">
<table style="border-collapse: collapse; font: 12px Tahoma;" border="1" cellspacing="5" cellpadding="5">
<tbody><tr>
<td>
<input name="uploadedimage" type="file">
</td>
</tr>
<tr>
<td>
<input name="Upload Now" type="submit" value="Upload Image">
</td>
</tr>
</tbody></table>
</form>
Save as saveimage.php
<?php
/**********MYSQL Settings****************/
$host="localhost";
$databasename="image";
$user="root";
$pass="";
/**********MYSQL Settings****************/
$conn=mysql_connect($host,$user,$pass);
if($conn)
{
$db_selected = mysql_select_db($databasename, $conn);
if (!$db_selected) {
die ('Can\'t use foo : ' . mysql_error());
}
}
else
{
die('Not connected : ' . mysql_error());
}
?>
<?php /*
function GetImageExtension($imagetype)
{
if(empty($imagetype)) return false;
switch($imagetype)
{
case 'image/bmp': return '.bmp';
case 'image/gif': return '.gif';
case 'image/jpeg': return '.jpg';
case 'image/png': return '.png';
default: return false;
}
} */
?>
<?php
error_reporting(0);
//include("mysqlconnect.php");
function GetImageExtension($imagetype)
{ if(empty($imagetype)) return false;
switch($imagetype)
{
case 'image/bmp': return '.bmp';
case 'image/gif': return '.gif';
case 'image/jpeg': return '.jpg';
case 'image/png': return '.png';
default: return false;
}
}
if (!empty($_FILES["uploadedimage"]["name"])) {
$file_name=$_FILES["uploadedimage"]["name"];
$temp_name=$_FILES["uploadedimage"]["tmp_name"];
$imgtype=$_FILES["uploadedimage"]["type"];
$ext= GetImageExtension($imgtype);
$imagename=date("d-m-Y")."-".time().$ext;
$target_path = "C:/wamp/www/imagefetch/IMAGE/".$imagename;
if(move_uploaded_file($temp_name, $target_path)) {
$query_upload="INSERT INTO `images_tbl`(`images_path`,`submission_date`) VALUES
('".$target_path."','".date("Y-m-d")."')";
mysql_query($query_upload) or die("error in $query_upload == ----> ".mysql_error());
echo "uploaded successfully";
}else{
exit("Error While uploading image on the server");
}
}
?>
<?php
///Code to use image name with new customized image name .
$imagename=date("d-m-Y")."-".time().$ext;
///Code to use image name as same as uploaded image name .
$imagename=$_FILES["uploadedimage"]["name"];
?>
Save as view.php to view image
<?php
/**********MYSQL Settings****************/
$host="localhost";
$databasename="image";
$user="root";
$pass="";
/**********MYSQL Settings****************/
$conn=mysql_connect($host,$user,$pass);
if($conn)
{
$db_selected = mysql_select_db($databasename, $conn);
if (!$db_selected) {
die ('Can\'t use foo : ' . mysql_error());
}
}
else
{
die('Not connected : ' . mysql_error());
}
?>
<?php
//include("mysqlconnect.php");
$select_query = "SELECT `images_path` FROM `images_tbl` ORDER BY `images_id` DESC";
$sql = mysql_query($select_query) or die(mysql_error());
while($row = mysql_fetch_array($sql)){
?>
<table style="border-collapse: collapse; font: 12px Tahoma;" border="1" cellpadding="5" cellspacing="5">
<tbody><tr>
<td>
<img src="<?=$row['images_path`']?>">
</td>
</tr>
</tbody></table>
<?php
}
?>
Subscribe to:
Posts (Atom)
