Pages

Thursday, 16 May 2013

My first poem

Mere kano m kuch aahat si hui mere kano m kuch aahat si hui so ke mai jaga uth ke mai bhaga dekha to wo angadai le rhi thi

Sunday, 12 May 2013

Pagination using php

Pagination is used when number of rows are maximum then these rows are divided into pages.
pagination is the important part of web development.(pagination in php,how to apply pagination in table using php)
Now lets try

<?php

       //connect to database
       // now start with query
               $rs=mysql_query("select * from table_name");

       //how many rows  you wants to show in one page. define a variable limit
               $limit=30;

      //how many rows are fetch into database.
$totalpage=mysql_num_rows($rs);
if($totalpage>$limit){
$totalPages=($totalpage/$limit);

      //check if pages are in float then add 1
                   if(is_float($totalPages)){
$totalPages=$totalPages+1;
}
} // end if

       // page is variable that contain page number
$page=(isset($_GET['page']))?(int) $_GET['page']:1;
$start =($page==1)?0:($page - 1) * $limit;

       //again apply query using limit

              $rs=mysql_query("select * from table_name  limit $start,$limit");

       while($row=mysql_fetch_array($rs)){

     //show data into table
   echo "<table><tr>";
   echo "<td>".$row["id"]."</td>";
           echo "<td>".$row["name"]."</td>";
                   echo "</tr></table>";

      //start a loop using variable $i
               for($i=1;$i<=$totalPages;$i++) { 
    ?>
                   <a href="<?php echo "page_name.php?page=$i" ?>" title=""><?php echo $i;  ?></a>

      <?php }  ?>




Saturday, 4 May 2013

Replace whitespace of string into dash or comma using php

Replaceing  whitespace into dash or comma this problem face by the beginners of php.now we try to solve this problem using php function.( whitespace in string,remove space from string.replace comma and dash place of whitespace.)

str_replace(find,replace,string) 

Exampal: First of all we take a string

<?php 
          // create php variable $str
          $str="This is only for test";
    
         // now set this string in str_replace
         $string=str_replace(" ","-",$str) ;
          echo $string;
?>

//output
This-is-only-for-test