Saturday, March 16, 2013

Mysql data 10 record per page


<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>pencil</title>
<script language="javascript" src="js/jquery.js"></script>
<script>

$(document).ready(function(){
  $("div a").click(function(){
$("div a").css("font-weight","normal");
$("div a").css("text-decoration","none");

    $(this).css("font-weight","bold");
$(this).css("text-decoration","underline");
$(this).attr("target","f1");
  });
});
</script>
<style>
.ss
{
color:blue;
}

.first a, .not_first a
{
text-decoration:none;
color:#c30;
font-family:Arial, Helvetica, sans-serif;
font-weight:normal;
font-size:12px;

}


.first a:hover, .not_first a:hover, .pp
{
text-decoration:underline;
height:20px;
width:20px;
font-weight:bold;
font-size:14px;

}
.first,.not_first:hover
{

text-decoration:underlinel;
font-weight:bold;
cursor:pointer;
height:15px;
width:15px;
float:left;
text-align:center;
padding:2px;
margin:2px;
}
.not_first
{
border:1px solid #C30;
background-color::#FFF
color:#C30;
font-weight:bold;
cursor:pointer;
float:left;
height:15px;
width:15px;
text-align:center;
padding:2px;
margin:2px;
line-height:15px;
}
</style>
</head>

<body>
<?php include("config.php");?>
<?php
mysql_connect($db_server,$db_user,$db_pass);

mysql_query("create database pagerank");
mysql_query("use ".$db);
mysql_query("create table abc (id int (255), data varchar (500)) if not exits ");

for($a=1;$a<=5;$a++)
{
/* remove this comment if u want to insert two*5 query at a time
mysql_query("insert into abc (data) values ('sudhir k gupta') ");
mysql_query("insert into abc (data) values ('rajesh k gupta') ");
*/
}


$a=mysql_num_rows(mysql_query("select * from abc"));
echo '<h3>total Data is '.$a.'<br />';
$limit1=0;
$limit2=$limit1+$data_per_page;
$page=$a/$data_per_page;
//$b=round($page,-0.5);
$b=$page;
$last_value=round($a,-0.5)/$data_per_page;
//echo ' b is'.$b.'<br />';
$result2=mysql_query("select * from abc limit 0,$b");
$result=mysql_query("select * from abc limit $limit1,$limit2");
while($row=mysql_fetch_array($result))
{
echo $row['id'].'-'. $row['data'];
echo '<br />';
}

for($c=0; $c<$b;$c++)
{
$d=$c+1;

if($c==$d)
{
echo '<div class="first all_page"><a href="index.php?num='.$c.'&subs='.$d.'" />'.$d.'</a></div>';
}
else
{
echo '<div class="not_first all_page"><a href="index.php?num='.$c.'&subs='.$d.'" />'.$d.'</a></div>';
}

}

?>

<?php
if(isset($_REQUEST['subs']))
{
$a=$_REQUEST['num'];
//$i=1;
$limit1=1;
$limit2=$a*$data_per_page;
$limit3=$limit2+$data_per_page;
echo 'limit '.$limit2.' to'.$limit3;
echo "<hr />";
$result=mysql_query("select * from abc limit $limit2,$data_per_page");
while($row=mysql_fetch_array($result))
{
echo $row['id'].'-'. $row['data'];
echo '<br />';
}
}
?>
<iframe src="" id="f1"></iframe>
</body>
</html>

add config file 

<?php
$db_server='127.0.0.1';
$db="pagerank";
$db_user="root";
$db_pass="";
$db_table="abc";
$data_per_page=2;

?>



<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>pencil</title>
</head>

<body>

<?php
mysql_connect("127.0.0.1","root","");

mysql_query("create database pagerank");
mysql_query("use pagerank");
mysql_query("create table abc (id int (255), data varchar (500)) if not exits ");
/*
for($a=1;$a<=2;$a++)
{
mysql_query("insert into abc (data) values ('sudhir k gupta') ");
mysql_query("insert into abc (data) values ('rajesh k gupta') ");
}
*/
mysql_query("use pagerank");

$a=mysql_num_rows(mysql_query("select * from abc"));
echo '<h3>total Data is '.$a.'<br />';
$limit1=0;
$limit2=$limit1+5;
$page=$a/5;
$b=round($page,0);
$result2=mysql_query("select * from abc limit 0,$b");
$result=mysql_query("select * from abc limit $limit1,$limit2");
while($row=mysql_fetch_array($result))
{
echo $row['id'].'-'. $row['data'];
echo '<br />';
}
echo '<table><tr>';
for($c=0; $c<=$b;$c++)
{
echo '<form action="" method="get">
<input type="hidden" value="'.$c.'" name="num" />
';
echo '<th><input type="submit" name="subs" value="'.$c.'" /></th></form>';
}
echo '</tr></table>';
?>

<?php
if(isset($_REQUEST['subs']))
{
$a=$_REQUEST['num'];
//$i=1;
$limit1=1;
$limit2=$a*10;
$limit3=$limit2+10;
echo 'limit '.$limit2.' to'.$limit3;
echo "<hr />";
$result=mysql_query("select * from abc limit $limit2,10");
while($row=mysql_fetch_array($result))
{
echo $row['id'].'-'. $row['data'];
echo '<br />';
}

}
?>
</body>
</html>

No comments:

Post a Comment