PageRenderTime 48ms CodeModel.GetById 21ms RepoModel.GetById 0ms app.codeStats 0ms

/part2/xml.php

https://bitbucket.org/wlynch92/cs336-dbproject
PHP | 77 lines | 58 code | 10 blank | 9 comment | 13 complexity | d8e5a071e4aa2854422b0e32c8947adf MD5 | raw file
  1. <?php
  2. $con = mysql_connect('cs336-64','csuser','cs277315');
  3. if (!$con){
  4. die(mysql_error());
  5. } else {
  6. //echo "Successful connection\n";
  7. }
  8. mysql_select_db("cs336",$con);
  9. $query = "SELECT *,DATE_FORMAT(birth,'%Y') AS byear FROM user";
  10. //echo $query."\n";
  11. $res = mysql_query($query,$con);
  12. // If any errors, exit. This includes empty results
  13. if (!$res){
  14. die(mysql_error());
  15. }
  16. echo "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n";
  17. echo "<Users>\n";
  18. /*for($i=0;$i<mysql_num_fields($res);$i++){
  19. echo mysql_field_name($res,$i)."\n";
  20. }
  21. */
  22. while ($row = mysql_fetch_assoc($res)){
  23. $uid=$row['uid'];
  24. echo "<User userID=\"".$uid."\">\n";
  25. echo "\t<FirstName>".$row['firstname']."</FirstName>\n";
  26. echo "\t<LastName>".$row['lastname']."</LastName>\n";
  27. if ($row['email']){
  28. echo "\t<EmailAddress>".$row['email']."</EmailAddress>\n";
  29. }
  30. //Do school query here
  31. $squery = "SELECT s.sname,a.degree,a.start,DATE_FORMAT(a.end,'%Y') AS end FROM attended a, school s, user u WHERE u.uid=a.uid AND s.sid=a.sid AND u.uid=$uid";
  32. $sres = mysql_query($squery,$con);
  33. if (mysql_num_rows($sres)>0){
  34. while ($srow = mysql_fetch_assoc($sres)){
  35. echo "\t<Education>\n";
  36. echo "\t\t<SchoolName>".$srow['sname']."</SchoolName>\n";
  37. if ($srow['degree']){
  38. echo "\t\t<Degree>".$srow['degree']."</Degree>\n";
  39. }
  40. if ($srow['end']){
  41. echo "\t\t<Year>".$srow['end']."</Year>\n";
  42. }
  43. echo "\t</Education>\n";
  44. }
  45. }
  46. //Do work query here
  47. $wquery = "SELECT c.employer_name,e.job_title,e.start,e.end FROM employment e, company c, user u WHERE u.uid=e.uid AND c.cid=e.cid AND u.uid=$uid";
  48. $wres = mysql_query($wquery,$con);
  49. if (mysql_num_rows($wres)>0){
  50. while ($wrow = mysql_fetch_assoc($wres)){
  51. echo "\t<WorkExperience>\n";
  52. echo "\t\t<CompanyName>".$wrow['employer_name']."</CompanyName>\n";
  53. echo "\t\t<Position>".$wrow['job_title']."</Position>\n";
  54. if ($wrow['start']){
  55. echo "\t\t<From>".$wrow['start']."</From>\n";
  56. }
  57. if ($wrow['end']){
  58. echo "\t\t<To>".$wrow['end']."</To>\n";
  59. }
  60. echo "\t</WorkExperience>\n";
  61. }
  62. }
  63. echo "</User>\n";
  64. }
  65. echo "</Users>\n";
  66. mysql_close($con);
  67. ?>