Wednesday, March 27, 2013

get and split url using javascript


<script>
function getPathFromUrl() {
  var url = window.location.href;


  if(url.indexOf("html") != -1)
     url = url.split(".")[0];

window.location.href;


  //return url;
}
$("#a").click(function(){
     alert(getPathFromUrl());//this will alert the url without querystring
});
</script>

any type of file restriction from server


RewriteEngine on
rewritecond %{http_host} ^www.domain.in [nc]
rewriterule ^(.*)$ http://domain.in/$1 [r=301,nc]


# Disable directory listing from this point
Options -Indexes

# Prevent viewing of htaccess file
<Files ~ "^\">
order allow,deny
deny from all
satisfy all
</Files>

# Force all PDF files to download
# Requires Apache Header Module - this will work for any file extensions
# below code it will automaticaly  download
<FilesMatch "\.(http://www.karyd.in?i:pdf)$">
  ForceType application/octet-stream
  Header set Content-Disposition attachment
</FilesMatch>

<FilesMatch \.(?i:gif|jpe?g|png|css|js)$>
    Order Deny,Allow
    Deny from all
</FilesMatch>

<FilesMatch /folder2/folder22/.*>
    Order Deny,Allow
     Deny from all
</FilesMatch>

<FilesMatch (robots\.txt)$>
    Order Deny,Allow
    Allow from all
</FilesMatch>

AuthType Basic
AuthName "Personal use"
AuthUserFile /full/path/to/.htpasswd
Require valid-user

Saturday, March 16, 2013

put intry number on every entry in mysql

you can say.. it will show the position of entry



SELECT
    @row_number := IFNULL(@row_number, 0) + 1 AS row_number,
    id,
    data
FROM abc
WHERE 1 = 1





entry_position id name
1 5255 sudhir
2 54585 mohan
here 1 and 2 will show automatically

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>

Friday, March 15, 2013

create DB, table and insert data using php


<?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') ");
}
?>

here i am using for loop. so that  i can insert many data at a time
set a<100. it will insert same data 100 time.

Mysql Delete Command

delete from abc
delete from abc where id between 1 and 10
delete from abc where id=1


abc is table name