PageRenderTime 89ms CodeModel.GetById 21ms RepoModel.GetById 1ms app.codeStats 0ms

/src/php/setup/makeParagraphText.php

https://bitbucket.org/silverasm/wordseer
PHP | 57 lines | 44 code | 6 blank | 7 comment | 0 complexity | 3eb9d69a036b5d2ebe27c6bdebbef137 MD5 | raw file
Possible License(s): Apache-2.0, LGPL-3.0, BSD-3-Clause
  1. <?php
  2. /* Copyright 2012 Aditi Muralidharan. See the file "LICENSE" for the full license governing this code. */
  3. /**************************************
  4. makeparagraphtext.php
  5. I only ran this once, to make paragraphs searchable as a unit.
  6. **************************************/
  7. include_once '../dbsetup.php';
  8. //makeParagraphText();
  9. function makeParagraphText(){
  10. $query = "SELECT * from paragraph;";
  11. $result = mysql_query($query) or die("<b>A fatal MySQL error occured</b>.
  12. <br/> Query: " . $query . "
  13. <br/> Error: (" . mysql_errno() . ") " . mysql_error());
  14. while($row = mysql_fetch_array($result)){
  15. $query = "SELECT sentence from sentence WHERE paragraph_id = ".$row['id'].";";
  16. $sentences = mysql_query($query) or die("<b>A fatal MySQL error occured</b>.
  17. <br/> Query: " . $query . "
  18. <br/> Error: (" . mysql_errno() . ") " . mysql_error());
  19. $paragraph = array();
  20. while($sentence = mysql_fetch_array($sentences)){
  21. array_push($paragraph, $sentence['sentence']);
  22. }
  23. $paragraph = join(" ", $paragraph);
  24. $query = "UPDATE paragraph SET text = '".mysql_real_escape_string($paragraph)."' WHERE id = ".$row['id'].";";
  25. mysql_query($query) or die("<b>A fatal MySQL error occured</b>.
  26. <br/> Query: " . $query . "
  27. <br/> Error: (" . mysql_errno() . ") " . mysql_error());
  28. echo $row['id'],"\n";
  29. }
  30. }
  31. //updateParagraphCount();
  32. function updateParagraphCount(){
  33. $query = "SELECT max(number) as paragraph_count, narrative_id from paragraph GROUP BY narrative_id;";
  34. $result = mysql_query($query);
  35. while($row = mysql_fetch_array($result)){
  36. $query = "UPDATE narrative SET paragraph_count = ".$row['paragraph_count']." WHERE id = ".$row['narrative_id'].";";
  37. mysql_query($query);
  38. echo $row['narrative_id'],"\n";
  39. }
  40. }
  41. setStartSentenceID();
  42. function setStartSentenceID(){
  43. $query = "SELECT min(id) as start, paragraph_id from sentence GROUP BY paragraph_id;";
  44. $result = mysql_query($query);
  45. while($row = mysql_fetch_array($result)){
  46. $query = "UPDATE paragraph SET start_sentence = ".$row['start']." WHERE id =".$row['paragraph_id'].";";
  47. mysql_query($query);
  48. echo $row['paragraph_id'],"\n";
  49. }
  50. }
  51. ?>