Thursday, 16 January 2014

PHP: Create, Edit, Delete & View step by step (Part 1)



How to create grid view.
There are the following step for create grid view.

  1. Step 1:-
                  create one  your databese.


  • Step 2:-(conn1.php)
     
                The following code for connection with mysql database.
                <?php
                $username = "root";
                $password = "root";
                $hostname = "localhost";
                   //connection to the database
                     $conn = mysql_connect($hostname, $username)
                      or die("Unable to connect to MySQL");
                     $retval = mysql_query($conn);
                             ?>

  • Step 3:- (v.php)
               Fetch data from tha database in table formate.
                          <table class="table" width="2000">
 <thead>
 <tr>
   <th width="3">COMPANY </th>
 <th width="3">ADDRESS </th>
 <th width="10">MODE</th>
 <th width="30">City</th>                                     

                                                                         <th  width="35">OFFICE PERSON</th>  
     <th width="35">Start Date</th>
  <th width="35">End  Date</th>

 
 </tr>
 </thead>
<?PHP
                                                         include("conn1.php");
                                                     mysql_select_db('ravi');
                                                   $s1 = "SELECT * FROM r2";
    //echo $sql;exit;
    $result = mysql_query($s1);
    while($row=mysql_fetch_array($result))
    {
    ?>
<tr>
          <td><?php echo $row['name']; ?></td>
          <td><?php echo $row['add']; ?></td>
          <td><?php echo $row['mode']; ?></td>
 <td><?php echo $row['zip']; ?></td>
 <td><?php echo $row['cperson']; ?></td>
 <td><?php echo $row['date1'];?> </td>
<td><?php echo $row['date2'];?> </td>
<td><a class="span3 typeahead" href="edit.php?no=<?php echo $row['no']; ?>"> Edit/More </a></td>
      <td><a class="span3 typeahead" href="delete.php?no=<?php echo $row['no']; ?>">Delete</a></td>
</tr>
</table>
Step 4:-(edit.php)
<?php
include ('conn1.php');
mysql_select_db('ravi');
if (isset($_GET["no"]))
{
    $sn = (int)$_GET["no"];
} else
{
    // no student number given. redirect someplace? show an error message?
}?>

Then here put your html code and put table.
<?PHP
 
    //echo $sql;exit;
    $id = $sn;
 $s1 = "SELECT * FROM r2 where no=$sn";
 $result = mysql_query($s1);
    while($row=mysql_fetch_array($result))
    {
    ?>
<tr>
<th align="right">ID:-</th>
<th><input type="text" name="us1" value="<?php echo $row['no']; ?>" disabled="disabled">//display no coloum from database
</th>
</tr>



No comments:

Post a Comment