Code.GeekInterview.com
  I am new, Sign me up!
 
Code Samples PHP
 

Customer List With Edit and Delete Options


Code ResourceAuthor: Lokesh M  

Difficulty Level:

Published: 25th May 2007   Read: 1271 times  

Filed in: PHP
Add Comment


 


ListCustomer displays list of customers and related information like address in alphabetical order.  It also provides option to edit and delete records while viewing the list simultaneously. ListCustomer takes in startchar as its argument - When startchar = "ALL", entire Customer table data is fetched and displayed on screen.

When startchar is any of the alphabet A to Z, then ListCustomer function fetches and displays only those Customer records that start with the startchar. For example if startchar = "A" then ListCustomer will fetch and display list of customers whose name start with "A"

 


Sample Code
  1.  
  2. <?php
  3.  
  4. function ListCustomer ($startchar) {
  5.     if ($startchar == "All") $sql = "SELECT * FROM `customers` Order by `Customer_Name`";
  6.     if ($startchar != "All") $sql = "SELECT * FROM `customers` WHERE mid(`Customer_Name`,1,1) = '".$startchar."' Order by `Customer_Name`";
  7.         if (!$result = @mysql_query($sql)) echo "<P>Error with query!";
  8.         $rows = @mysql_numrows($result);
  9.         if($rows == 0) {
  10.                 echo "<BR><BR><P Align=Center>There are no entries in your customer.";
  11.         } else {
  12. ?>
  13.    
  14.     <Table width="90%" align="center" bgcolor="#F1F2ED" ><TR Align="Center">
  15.     <? for($i=65; $i <= 90; $i++) { ?>
  16.     <TD bgcolor="#ECE9D8" bordercolor="#ACA899" Width="25"><font face="Arial" size="2pt"> <B><a href=Customerdb.php?action=Show&startchar=<? echo chr($i) ?>><? echo chr($i) ?></B></a></font></TD>
  17.     <? } ?>
  18.     </TR></table>
  19.  
  20.     <table bgcolor="#F1F2ED" width=90% align=center>
  21.     <tr align="Center" bgcolor="#CECECE"><th><font face="Arial" size="2pt">ID</th>
  22.         <th><font face="Arial" size="2pt">Customer Name</font></th>
  23.         <th><font face="Arial" size="2pt">Add1</font></th>
  24.         <th><font face="Arial" size="2pt">Add2</font></th>
  25.         <th><font face="Arial" size="2pt">Add3</font></th>
  26.         <th><font face="Arial" size="2pt">City</font></th>
  27.         <th><font face="Arial" size="2pt">Pin</font></th>
  28.         <th><font face="Arial" size="2pt">E</font></th>
  29.         <th><font face="Arial" size="2pt">D</font></th></tr>
  30.         <?
  31.         $i=1;
  32.         while($row = @mysql_fetch_array($result)) { ?>
  33.             <tr>
  34.             <?if (fmod ($i,2) == 0) echo '<td bgcolor="#F1EFE2"><font face="Tahoma" size="2pt">'.$row['CustomerID']; else echo '<td bgcolor="#FFFFFF"><font face="Tahoma" size="2pt">'.$row['CustomerID'];?></td>
  35.             <?if (fmod ($i,2) == 0) echo '<td bgcolor="#F1EFE2"><font face="Tahoma" size="2pt">'.substr($row['Customer_Name'],0,25); else echo '<td bgcolor="#FFFFFF"><font face="Tahoma" size="2pt">'.substr($row['Customer_Name'],0,25);?></b></td>
  36.             <?if (fmod ($i,2) == 0) echo '<td bgcolor="#F1EFE2"><font face="Tahoma" size="2pt">'.substr($row['Add1'],0,25); else echo '<td bgcolor="#FFFFFF"><font face="Tahoma" size="2pt">'.substr($row['Add1'],0,25);?></td>
  37.             <?if (fmod ($i,2) == 0) echo '<td bgcolor="#F1EFE2"><font face="Tahoma" size="2pt">'.substr($row['Add2'],0,20); else echo '<td bgcolor="#FFFFFF"><font face="Tahoma" size="2pt">'.substr($row['Add2'],0,20);?></td>
  38.             <?if (fmod ($i,2) == 0) echo '<td bgcolor="#F1EFE2"><font face="Tahoma" size="2pt">'.substr($row['Add3'],0,20); else echo '<td bgcolor="#FFFFFF"><font face="Tahoma" size="2pt">'.substr($row['Add3'],0,20);?></td>
  39.             <?if (fmod ($i,2) == 0) echo '<td bgcolor="#F1EFE2"><font face="Tahoma" size="2pt">'.substr($row['City'],0,10); else echo '<td bgcolor="#FFFFFF"><font face="Tahoma" size="2pt">'.substr($row['City'],0,10);?></td>
  40.             <?if (fmod ($i,2) == 0) echo '<td bgcolor="#F1EFE2"><font face="Tahoma" size="2pt">'.substr($row['Pin'],0,7); else echo '<td bgcolor="#FFFFFF"><font face="Tahoma" size="2pt">'.substr($row['Pin'],0,7);?></td>
  41.             <?if (fmod ($i,2) == 0) echo '<td bgcolor="#F1EFE2"><font face="Tahoma" size="2pt"> <a href=Customerdb.php?action=Modify&cid='.$row['CustomerID'].'><img src="images/b_edit.png" alt="Edit" border=0></a>';?></td>
  42.             <?if (fmod ($i,2) != 0) echo '<td bgcolor="#FFFFFF"><font face="Tahoma" size="2pt"> <a href=Customerdb.php?action=Modify&cid='.$row['CustomerID'].'><img src="images/b_edit.png" alt="Edit" border=0></a>';?></td>
  43.             <?if (fmod ($i,2) == 0) echo '<td bgcolor="#F1EFE2"><font face="Tahoma" size="2pt"> <a href=Customerdb.php?action=Delete&cid='.$row['CustomerID'].'&cname='.urlencode($row['Customer_Name']).'><img src="images/b_drop.png" alt="Delete" border=0></a>';?></td>
  44.             <?if (fmod ($i,2) != 0) echo '<td bgcolor="#FFFFFF"><font face="Tahoma" size="2pt"> <a href=Customerdb.php?action=Delete&cid='.$row['CustomerID'].'&cname='.urlencode($row['Customer_Name']).'><img src="images/b_drop.png" alt="Delete" border=0></a>';?></td>
  45.             <?$i++;?>
  46.             </font></tr>
  47.         <? } ?>
  48.         </table></font>
  49.     <?
  50.     }
  51. }
  52. ?>
  53.  
Copyright GeekInterview.com


Next Article: PHP Code Snippet Library


 

Latest Code Samples

 

Popular Code Samples

 

Related Code Samples

 

Post Comment


Members Please Login

Name:  Email: (Optional. Used for Notification)

Title:
 
Comment:
Validation Code: <=>  (Enter this code in text box)





Popular Coders

# Coder NameHits
1. chowsys7299
2. jijo chacko4019
3. Lokesh M2284
4. jayantg1474

Active Coders

# Coder NameCodes
1. chowsys6
2. Lokesh M2
3. jayantg1
4. jijo chacko1

Refined Tags

 

Sponsored Links

 
About Us -  Privacy Policy -  Terms and Conditions -  Contact  

Copyright © 2005 - 2009 GeekInterview.com. All Rights Reserved

Page copy protected against web site content infringement by Copyscape