Wednesday 16 April 2014

Complete jquery form & data delivery

<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.11.0/jquery.min.js">
</script>
<script>
$(document).ready(function(){
  $("button").click(function(){
    $("#result").load("test.php");
  });
 
  $("#test").click(function(){
       

    //form_submit("reg","test.php");
   
    //get_form("test1.php","result");
   
    //$.ajax({type:"POST",url:"test.php", data: $("#reg").serialize(),success: function(data){alert(data);}});
   
    //$.ajax({type:"GET",url:"test1.php", success: function(data){alert(data);}});

    return false;
   
  });
 
  function  form_submit(form_id,filename,output)
  {

    $.post(filename,$("#"+form_id).serialize(), function(data){if(output){$("#"+output).html(data);}else{alert(data);}});
    }
   
   
    function get_form(filename,output)
    {
       
        $.get(filename, function(data){if(output){$("#"+output).html(data);}else{alert(data);}});
       
    }
 

 
 
});


 function numbersonly(e)
  {
        var unicode=e.charCode? e.charCode : e.keyCode
        if (unicode!=8){ //if the key isn't the backspace key (which we should allow)
        if (unicode<48||unicode>57) //if not a number
        return false //disable key press
        }
    }

</script>
</head>
<body>


<table width="386" border="1">
  <tr>
    <td width="376" height="74"><div id="result"></div></td>
  </tr>
  <tr>
    <td height="25"><button>Get External Content</button></td>
  </tr>
  <tr>
    <td>
   
<form method="post" id="reg">
<input type="text" name="name">

Number <input type="text" name="number" onKeyPress="return numbersonly(event)">
<input type="submit" value="Post Method" id="test">
</form>



</td>
  </tr>
  <tr>
    <td>&nbsp;</td>
  </tr>
  <tr>
    <td>&nbsp;</td>
  </tr>
</table>









</body>

Tuesday 15 April 2014

Tree Structure Menu with php Using Recursive

<code>
CREATE TABLE IF NOT EXISTS `menu` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `id_parent` int(11) NOT NULL DEFAULT '0',
  `link` varchar(255) NOT NULL,
  `order` int(11) NOT NULL DEFAULT '0',
  `title` varchar(255) CHARACTER SET utf8 COLLATE utf8_polish_ci NOT NULL DEFAULT '',
  `level` tinyint(4) NOT NULL DEFAULT '0',
  PRIMARY KEY (`id`)
) ENGINE=InnoDB  DEFAULT CHARSET=latin1 AUTO_INCREMENT=24 ;



INSERT INTO `menu` (`id`, `id_parent`, `link`, `order`, `title`, `level`) VALUES
(12, 0, '', 0, 'Office Furniture', 0),
(13, 12, '', 0, 'Chairs', 0),
(14, 12, '', 0, 'Work Tables', 0),
(15, 12, '', 0, 'Workstations', 0),
(16, 12, '', 0, 'Storage', 0),
(17, 12, '', 0, 'Conference Tables', 0),
(18, 13, '', 0, 'with spagh', 0),
(19, 13, '', 0, 'without spagh', 0),
(20, 18, '#', 0, 'Triangle', 0),
(21, 18, '#', 0, 'Sqare', 0),
(22, 19, '#', 0, 'Simple', 0),
(23, 19, '#', 0, 'Complex', 0);




</code>

PHP Code for that example


<code>



<?php

        $db = new PDO('mysql:dbname=test13', 'root', '',
    array(PDO::MYSQL_ATTR_INIT_COMMAND => "SET NAMES utf8"));


function createsubmenu( $item )
{
    global $db;
// prepare a query to get subitems of the current $item (those with parent = $item)
    $subsel = $db->prepare('SELECT id, link, title, level  FROM menu WHERE id_parent = :parent ORDER BY `order`');
// run the query
    $subsel->execute(array('parent' => $item));
    $text = '';
// fetch one row at a time, when no more rows are available $i
// will be false and while ends
    while( ($i = $subsel->fetch(PDO::FETCH_OBJ)) !== false ) {
// generate code for the current $item
// will recursively call createsubmenu to add possibly existing subitems
        $text .= '<li class="menucolor' . ($i->level - 1) . '">'
            .'<a href="' . htmlspecialchars($i->link) . '">' . htmlspecialchars($i->title) . '</a>'
            . createsubmenu($i->id) . '</li>';
    }
// there were no items for the current call
    if( $text == '' )
        return '';
// items were found, wrap them in an unordered list
    return '<ul id="red" class="treeview-red">' . $text . '</ul>';
}

echo createsubmenu(0);
?>
</code>


I have recently modified code So, that you get the same result with minimum query from the database.





OUT LIKE THIS


Monday 2 December 2013

Add New items in the buddy member menu

In the buddypress there is need to add certain new functionality in the buddypress there need to custmize the inbuilt functions. So i show you a code with the help of that i was successfull to add new menu in the buddypress member menu.

 
<?php


function my_setup_nav() {
      global $bp;

      bp_core_new_nav_item( array( 
            'name' => __( 'Item One', 'buddypress' ), 
            'slug' => 'my-item-one', 
            'position' => 30, 
            'screen_function' => 'my_item_one_page', 
      ) );

      bp_core_new_nav_item( array(
            'name' => __( 'Item Two', 'buddypress' ),
            'slug' => 'my-item-two',
            'position' => 20,
            'screen_function' => 'my_item_two_template' 
      ) );

      // Change the order of menu items
      $bp->bp_nav['settings']['position'] = 100;

      // Remove a menu item
      $bp->bp_nav['activity'] = false;

      // Change name of menu item
      $bp->bp_nav['groups']['name'] = 'community';
}

add_action( 'bp_setup_nav', 'my_setup_nav' );


// Load a page template for your custom item. You'll need to have an item-one-template.php and item-two-template.php in your theme root.
function my_item_one_template() {
      bp_core_load_template( 'item-one-template' );
}

function my_item_two_template() {
      bp_core_load_template( 'Sign-Up' );
}

?>



Tuesday 19 November 2013

CSS Code for fixed div in ie6 browser

<!DOCTYPE HTML>
<html>
<head>
 <title>Using CSS Fixed Position Across Browsers</title>
 <style type="text/css">

  div.fixed-position {
   background-color: #F0F0F0 ;
   border: 1px solid #CCCCCC ;
   height: 48px ;
   line-height: 50px ;
   position: fixed ;
   text-align: center ;
   width: 148px ;
   z-index: 1000 ;
   }

  div.fixed-n {
   left: 50% ;
   margin-left: -75px ;
   top: 0px ;
   }

  div.fixed-n-e {
   right: 0px ;
   top: 0px ;
   }

  div.fixed-e {
   margin-top: -25px ;
   right: 0px ;
   top: 50% ;
   }

  div.fixed-s-e {
   bottom: 0px ;
   right: 0px ;
   }

  div.fixed-s {
   bottom: 0px ;
   left: 50% ;
   margin-left: -75px ;
   }

  div.fixed-s-w {
   bottom: 0px ;
   left: 0px ;
   }

  div.fixed-w {
   margin-top: -25px ;
   left: 0px ;
   top: 50% ;
   }

  div.fixed-n-w {
   left: 0px ;
   top: 0px ;
   }

 </style>

 <!--
  IE-6 Hacks.
  NOTE: I am using the "_" hack here because my version of
  IE "stand alone" doesn't seem to support conditional
  comments: [if lt IE 7.0].

  Tip gotten from:
  http://www.howtocreate.co.uk/fixedPosition.html
 -->
 <style type="text/css">

  body {
   _background-color: gold ;
   }

  div.fixed-position {
   _position: absolute ;
   }

  div.fixed-n-w,
  div.fixed-n,
  div.fixed-n-e {
   _top: expression( ie6 = (document.documentElement.scrollTop + "px") ) ;
   }

  div.fixed-e,
  div.fixed-w {
   _top: expression( ie6 = (document.documentElement.scrollTop + (document.documentElement.clientHeight / 2) + "px") ) ;
   }

  div.fixed-s-w,
  div.fixed-s,
  div.fixed-s-e {
   _bottom: auto ;
   _top: expression( ie6 = (document.documentElement.scrollTop + document.documentElement.clientHeight - 52 + "px") ) ;
   }

 </style>
</head>
<body>

 <div class="fixed-position fixed-n">
  North
 </div>

 <div class="fixed-position fixed-n-e">
  North East
 </div>

 <div class="fixed-position fixed-e">
  East
 </div>

 <div class="fixed-position fixed-s-e">
  South East
 </div>

 <div class="fixed-position fixed-s">
  South
 </div>

 <div class="fixed-position fixed-s-w">
  South West
 </div>

 <div class="fixed-position fixed-w">
  West
 </div>

 <div class="fixed-position fixed-n-w">
  North West
 </div>

 <!-- ------- -->
 <!-- ------- -->

 <div style="height: 3000px ;">
  . <!--- To force scrolling. ---> .
 </div>

</body>
</html>

Source: http://www.bennadel.com/blog/1734-Using-CSS-Fixed-Position-Elements-Across-Browsers.htm

Monday 18 November 2013

PHP code for backup of mysql database with structure

When you running a medium internet based application then you very important to backup of the database so that whenever the application is enfacted or create a problem . then you can just restore the application using our old database backup. To day i show you simple code help to backup of your database. In this code main thing is that it create two copy of the database backup file one copy for the user and also one copy save at the server side.

There is different format are available like excel,text,sql etc. There is choice of the user in which format save the database backup file.But mysql accept each format.

<?php

backup_tables('localhost','root','','tyre1');


/* backup the db OR just a table */
function backup_tables($host,$user,$pass,$name,$tables = '*')
{
   
    $link = mysql_connect($host,$user,$pass);
    mysql_select_db($name,$link);
   
    //get all of the tables
    if($tables == '*')
    {
        $tables = array();
        $result = mysql_query('SHOW TABLES');
        while($row = mysql_fetch_row($result))
        {
            $tables[] = $row[0];
        }
    }
    else
    {
        $tables = is_array($tables) ? $tables : explode(',',$tables);
    }
   
    //cycle through
    foreach($tables as $table)
    {
        $result = mysql_query('SELECT * FROM '.$table);
        $num_fields = mysql_num_fields($result);
       
        //$return.= 'DROP TABLE '.$table.';';
        $row2 = mysql_fetch_row(mysql_query('SHOW CREATE TABLE '.$table));
        $return.= "\n\n".$row2[1].";\n\n";
       
        for ($i = 0; $i < $num_fields; $i++)
        {
            while($row = mysql_fetch_row($result))
            {
                $return.= 'INSERT INTO '.$table.' VALUES(';
                for($j=0; $j<$num_fields; $j++)
                {
                    $row[$j] = addslashes($row[$j]);
                    $row[$j] = ereg_replace("\n","\\n",$row[$j]);
                    if (isset($row[$j])) { $return.= '"'.$row[$j].'"' ; } else { $return.= '""'; }
                    if ($j<($num_fields-1)) { $return.= ','; }
                }
                $return.= ");\n";
            }
        }
        $return.="\n\n\n";
    }
   
    $ext=str_replace(' ',':',date("Y-m-d H:i:s"));
     
    //save file
   
    $handle = fopen('db-backup-'.time().'-'.(md5(implode(',',$tables))).'.sql','w+');
    fwrite($handle,$return);
    fclose($handle);
    $name='db-backup-'.time().'-'.(md5(implode(',',$tables))).'.sql';
    echo "<a href='$name'>".$name."</a>";
    echo "<script>window.location='".$name."';</script>";
}


?>

Tuesday 11 June 2013

Jquery framework increase robustness in your application

Now a days website is compulsory for every organization as well as the individual. Its same as the real wold in the real world people know each other because the people interact each other. There is various occasions on which we meet each other like birthday celebration on different festivals. On different occasions the people share our identity to each other so that the people know each other. So today era large number of website and applications are developing.


Wednesday 1 May 2013

Php code for uploading the files


Whenever you create a website then there is need to dynamicity. If your sites only provides the information for the then it’s only the informational site. Such type of sites only used for the one way from that sites you can provide the information but you can’t get the user responses. For adding the dynamicity use form in the website. With the help of form user can send the data to the server.

There is providing the code from which upload the picture document or you use this code according to your requirement.

 Step 1: First of create the file upload.php
               In this file we write the code for uploading the picture in html format. This is as                 
               given below.


            <form method="post" action="<?php ?>" enctype="multipart/form-data">
<input type="file" name="file" />

<input type="submit" name="send" value="send" />


</form>

Step 2:  Now need to add php code so that wen you take the action it work out.



<?php

if(isset($_POST['send']))
{
 if(($_FILES["file"]["type"]=="image/jpeg")|| ($_FILES["file"]["type"]=="image/png") || ($_FILES["file"]["type"]=="image/jpg")&&($_FILES["file"]["size"]<1024))
 {


                        if($_FILES["file"]["error"]>0)
                        {
                        echo $_FILES["file"]["error"];
                        }
                        else
                        {
                       
                                                if(file_exists("upload/".$_FILES["file"]["name"]))
                                                {
                                                echo "File already present";
                                                }
                                                else
                                                {
                                                move_uploaded_file($_FILES["file"]["tmp_name"],"upload/".$_FILES["file"]["name"]);
                                                echo "File is uploaded";
                                               
                                                }
                       
                       
                        }
 
 }
 else
 {
 echo "File not a valid";
 }

}

?>