Advertisement
Guest User

showfriends

a guest
Feb 19th, 2013
45
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.24 KB | None | 0 0
  1. sub showfriends
  2. {
  3. #start html table
  4. print qq~<html>
  5. <head>
  6. <Title>My Friends</Title>
  7. </head>
  8. <body>
  9. <table border=1>
  10. <tr>
  11. <th>ID</th><th>Last Name</th><th>First Name</th><th>Phone Number</th><th>Email</th>
  12. </tr>~;
  13.  
  14. #form SQL Select Statement
  15. $select = qq~select id, lname, fname, phone, email from friends~;
  16.  
  17. #connect to MySQL and create a DB handler $dbh
  18. $dbh=DBI->connect($connectionInfo,$user,$passwd);
  19.  
  20. #prepare MySQL statement and create Statement Handler $sth
  21. $sth=$dbh->prepare($select);
  22.  
  23. #Execute select statement
  24. $sth->execute();
  25.  
  26. #Loop through each record selected and print in html table
  27. while (@row=$sth->fetchrow_array())
  28. {
  29. print qq~<tr>
  30. <td>$row[0]</td><td>$row[1]</td><td>$row[2]</td>
  31. <td>$row[3]</td><td>$row[4]</td>
  32. </tr>~;
  33. }
  34.  
  35. #close HTML table
  36. print qq~</table>
  37. </body>
  38. </html>~;
  39.  
  40. $dbh->disconnect();
  41. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement