While we work on some custom php or mysql projects then often we require to make transaction or actions reports based on dates and date range. Like Daily, yesterday’s, last seven day’s, last months, last 3 month’s etc. We can do that easily with sql queries describe in todays MySQL Tips on Date
All posts tagged mysql
Pagination with jQuery, MySQL and PHP
From many days i am thinking to make a pagination script using php and jquery. Today i am making a pagination script for you. How to implement Pagination with jQuery, PHP and MySQL. It is a simple tutorial. It’s looks big but very simple script. Take a look at this screen shot.

The tutorial contains three PHP files and two js files and one css file includes jQuery plugin.
-config.php (Database Configuration)
-pagination.php
-pagination_data.php
-jquery.js
-jquery_pagination.js
–style.css
We also include the database script in the download zip file with data so that you can run this code and check.
[smProductImageAdd src="http://learneveryday.net/codecanyon/adverticement/add_codecnayon_smart-social-share-asp.net.png" alt= "Smart Social Share" href="http://codecanyon.net/item/php-smart-social-share/202558" title="Smart Social Share (Php Plugin)" description="Smart Social share is a php plugin . Which helps you to give user to share your content with social book mark site. There are 4 plugin in this package." ref="marifdu"]
Database Table
CREATE TABLE IF NOT EXISTS `northwind_products` ( `ProductID` int(1) NOT NULL AUTO_INCREMENT, `ProductName` varchar(256) NOT NULL, `UnitPrice` decimal(4,2) NOT NULL, `UnitsInStock` int(10) NOT NULL, PRIMARY KEY (`ProductID`) ) ENGINE=MyISAM DEFAULT CHARSET=latin1 AUTO_INCREMENT=78 ;
jquery_pagination.js
Contains javascript this script works like a data controller.
$(document).ready(function()
{
//Data Loading Image
function Data_Load()
{
$("#loading").fadeIn(900,0);
$("#loading").html('<img src="bigLoader.gif" />');
}
//Hide Loading Image
function Hide_Load()
{
$("#loading").fadeOut('slow');
};
//Default Starting Page Results
$("#pagination li:first")
.css({'color' : '#FF0084'}).css({'border' : 'none'});
Data_Load();
$("#content").load("pagination_data.php?page=1", Hide_Load());
//Pagination Click
$("#pagination li").click(function(){
Data_Load();
//CSS Styles
$("#pagination li")
.css({'border' : 'solid #dddddd 1px'})
.css({'color' : '#0063DC'});
$(this)
.css({'color' : '#FF0084'})
.css({'border' : 'none'});
//Loading Data
var pageNum = this.id;
$("#content").load("pagination_data.php?page=" + pageNum, Hide_Load());
});
});
config.php
You have to change hostname, username, password and databasename.
<?php
$mysql_hostname = "localhost";
$mysql_user = "root";
$mysql_password = "";
$mysql_database = "learneveryday_tutorial";
$db = mysql_connect($mysql_hostname, $mysql_user, $mysql_password)
or die('Error connection to database server: ' . mysql_error());
mysql_select_db($mysql_database, $db)
or die('Error connection to database server: ' . mysql_error());
?>
pagination.php
User interface page.
<?php
include('config.php');
$per_page = 10;
//Calculating no of pages
$sql = "select count(*) from northwind_products";
$result = mysql_query($sql);
$count = mysql_fetch_row($result);
$pages = ceil($count[0]/$per_page);
?>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.3.0/jquery.min.js"></script>
<script type="text/javascript" src="jquery_pagination.js"></script>
<link rel="stylesheet" href="style.css" type="text/css" />
<div id="loading" ></div>
<div id="content" ></div>
<ul id="pagination">
<?php
//Pagination Numbers
for($i=1; $i<=$pages; $i++)
{
echo '<li id="'.$i.'">'.$i.'</li>';
}
?>
</ul>
pagination_data.php
Simple php script display data from the messages table.
<?php
include('config.php');
$per_page = 10;
if($_GET)
{
$page=$_GET['page'];
}
$start = ($page-1)*$per_page;
$sql = "select * from northwind_products order by ProductID limit $start,$per_page";
$result = mysql_query($sql);
?>
<table width="800px">
<?php
while($row = mysql_fetch_array($result))
{
$ProductID=$row['ProductID'];
$ProductName=$row['ProductName'];
?>
<tr>
<td><?php echo $ProductID; ?></td>
<td><?php echo $ProductName; ?></td>
</tr>
<?php
}
?>
</table>
CSS Code
CSS code for page numbers.
#loading
{
width: 100%;
position: absolute;
}
li
{
list-style: none;
float: left;
margin-right: 16px;
padding:5px;
border:solid 1px #dddddd;
color:#0063DC;
}
li:hover
{
color:#FF0084;
cursor: pointer;
}
You can download the full code from bellow link.
MySQL Database Administration using Visual Studio 2005
1. Download and install:
MySQL Connector/ODBC 3.51
2. In the ODBC Administrator, under “System DSN” click Add then select the MySQL driver

3. On the next screen enter the information to connect to your MySQL database

4. In Visual Studio 2005, Select the Server Tab

5. Right-click on “Data Connections” and select “Add Connection”

6. Click the ‘change” button

7. Select “Microsoft ODBC Data Source”

8. Select your ODBC entry you created in the earlier step

9. You can now use the query designer in Visual Studio

Insert in to MySQL with ASP.NET – Part 2
In this tutorial we use the previous tutorial form. And modify the c# code to insert data in mysql using store procedure. Normally we use phpmyadmin. But using phpmyadmin we do not see the storeprocedure. To create storeprocedure we have to use MySQL Administrator. You can download mysql-gui-tools-5.0-r17-win32.msi from mySql site.
Here we just give the save button code
try
{
// Connection string for a typical local MySQL installation
string cnnString = "Server=localhost;Port=3306;Database=ci_series;Uid=root;Pwd=";
// Create a connection object
MySqlConnection connection = new MySqlConnection(cnnString);
// call store procedure
MySqlCommand cmd = new MySqlCommand("insert_membership", connection);
cmd.CommandType = CommandType.StoredProcedure;
cmd.Parameters.Add("?first_name", MySqlDbType.VarChar).Value = txtFirstName.Text;
cmd.Parameters.Add("?last_name", MySqlDbType.VarChar).Value = txtLastName.Text;
cmd.Parameters.Add("?username", MySqlDbType.VarChar).Value = txtUserName.Text;
cmd.Parameters.Add("?password", MySqlDbType.VarChar).Value = txtPassword.Text;
cmd.Parameters.Add("?email_address", MySqlDbType.VarChar).Value = txtEmail.Text;
connection.Open();
int result = cmd.ExecuteNonQuery();
lblError.Text = "Data Saved";
}
catch (Exception ex)
{
lblError.Text = ex.Message;
}
Create a store procedure using MySQL Administrator. The code is bellow.
DELIMITER $$ DROP PROCEDURE IF EXISTS `insert_membership` $$ CREATE DEFINER=`root`@`localhost` PROCEDURE `insert_membership`( IN first_name varchar(25), IN last_name varchar(25), IN username varchar(25), IN password varchar(10), IN email_address varchar(50) ) BEGIN INSERT INTO membership ( first_name, last_name, username, password, email_address ) VALUES( first_name, last_name, username, password, email_address ) ; END $$ DELIMITER ;
Here is a screen shot of the store procedure inside mysql administrator.

After insert data using store procedure you can see the successful message like bellow.

To learn more about store procedure you can read Stored Procedure Parameters and
MySQL Stored Procedure – INSERT – Example
Bellow is the link to download the sample code used in this tutorial.
Insert in to MySQL with ASP.NET – Part 1
Introduction
MySQL is one of the most popular open source databases available. With the release of version 5.0, MySQL adds new features, such as stored procedures, triggers, and user-defined functions, making it more comparable to commercial database server systems. Many Web hosting companies offer MySQL, and it is a compelling solution as well as a great way to learn SQL.
In this series of articles, I want to introduce you to using MySQL 5.0 with ASP.NET. I hope to cover the most common uses for MySQL, as well as take advantage of some of the new features in version 5.0. To do this, we will look at creating a database of Bible verses and ASP.NET pages to view and manage the verses.
Tools Needed
To begin development, you will need to have the following tools.
Continue reading →


