Advertisement
Guest User

Untitled

a guest
Sep 30th, 2017
125
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.65 KB | None | 0 0
  1. $dbServername = "localhost";
  2. $dbUsername = "username";
  3. $dbPassword = "password";
  4. $dbName = "editabletext";
  5.  
  6. $conn = mysqli_connect($dbServername, $dbUsername, $dbPassword, $dbName);
  7.  
  8. if ($conn->connect_error) {
  9. die("Connection failed: " . $conn->connect_error);
  10. }
  11. $query = "SELECT raceScheduleLink FROM news";
  12. $result = mysqli_query($conn, $query);
  13.  
  14. if($row = mysqli_fetch_array($result)) {
  15. $linkArray = Array();
  16. while ($row = mysqli_fetch_array($result, MYSQLI_ASSOC)) {
  17. $linkArray[] = $row['raceScheduleLink'];
  18. //print_r($linkArray);
  19. }
  20. }
  21.  
  22. $query = "SELECT raceScheduleText FROM news";
  23. $result = mysqli_query($conn, $query);
  24.  
  25. if($row = mysqli_fetch_array($result)) {
  26. $titleArray = Array();
  27. while ($row = mysqli_fetch_array($result, MYSQLI_ASSOC)) {
  28. $titleArray[] = $row['raceScheduleText'];
  29. //print_r($titleArray);
  30. }
  31. }
  32.  
  33.  
  34. $dom = new DOMDocument('1.0');//Create new document with specified version number
  35.  
  36. $p_text = $titleArray[0];
  37. $p = $dom->createElement('a', $p_text);//Create new <p> tag with text
  38. $domAttribute = $dom->createAttribute('id');//Create the new attribute 'id'
  39. $domAttribute->value = 'description';//Add value to attribute
  40. $p->appendChild($domAttribute);//Add the attribute to the p tag
  41. $p->setAttribute('href', $linkArray[0]);
  42. $dom->appendChild($p);//Add the p tag to document
  43. echo $dom->saveHTML(); //Outputs the generated source code
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement