Advertisement
Guest User

Untitled

a guest
Sep 21st, 2017
65
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.31 KB | None | 0 0
  1. print('N. of records: '.$result->num_rows.'<br />');
  2. print('<table>');
  3. while ($row = $result->fetch_object()){
  4. print('<tr><td>'.$row['last'].'</td><td>'.$row['first'].'</td></tr>');
  5. }
  6. print('</table>');
  7.  
  8. <html>
  9. <body>
  10.  
  11. <?php
  12.  
  13. $dbhost = 'localhost:3306';
  14. $username = "root";
  15. $password = "";
  16. $database = "newworld";
  17.  
  18. $conn =mysqli_connect($dbhost, $username, $password, $database);
  19.  
  20. if(! $conn ) {
  21. die('Could not connect: ' . mysqli_error());
  22. } else {
  23. #db connected
  24. }
  25.  
  26. /**/
  27. $sql = 'SELECT first, last FROM photos';
  28. $result = mysqli_query($conn, $sql);
  29.  
  30. /**/
  31.  
  32. ?>
  33.  
  34. <table border="1" cellspacing="2" cellpadding="2">
  35. <tr>
  36. <td><font face="Arial, Helvetica, sans-serif"><u>first</u></font></td>
  37. <td><font face="Arial, Helvetica, sans-serif"><u>last</u></font></td>
  38. </tr>
  39.  
  40. <?php
  41.  
  42. if (mysqli_num_rows($result) > 0) {
  43.  
  44. while($row = mysqli_fetch_assoc($result)) {
  45.  
  46. ?>
  47.  
  48. <tr>
  49. <td><font face="Arial, Helvetica, sans-serif"><?php echo $row["first"]; ?></font></td>
  50. <td><font face="Arial, Helvetica, sans-serif"><?php echo $row["first"]; ?></td>
  51. </tr>
  52.  
  53. <?php
  54. }
  55.  
  56. } else {
  57. echo "0 results";
  58. }
  59. ?>
  60. </table>
  61. </body>
  62. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement