Advertisement
Guest User

Untitled

a guest
May 15th, 2017
69
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.89 KB | None | 0 0
  1. <?php
  2.  
  3. //connection parameters
  4.  
  5.  
  6. // include some php
  7. include 'php_include.php';
  8.  
  9. echo '<div style="background:#ecc;border: 4px solid #dbb;">';
  10.  
  11. function dbConnect(){
  12.  
  13. $hostname = 'localhost';
  14. $username = 'tbcj857';
  15. $mysql_pass = 'm2d59';
  16. $database = 'tbcj857';
  17.  
  18. $conx = mysql_connect ($hostname , $username, $mysql_pass)
  19.    or die ("Can't connect to MySQL" . mysql_error() );
  20.  
  21. mysql_select_db ($database)
  22.    or die ("Can't select that database" . mysql_error() );   
  23.  
  24. return $conx;
  25.  
  26. }
  27.  
  28. dbConnect();
  29.  
  30. $sql = "SELECT users.id, users.fname, users.lname, posts.post_title
  31.     FROM users INNER JOIN posts
  32.     ON users.id = posts.user_id";
  33.  
  34. $result = mysql_query($sql) or die (mysql_error() );
  35.  
  36. while ($row = mysql_fetch_assoc($result) ) {
  37.  
  38. echo $row['posts.post_title'] . <br/>  . $row['users.fname'] . $row['users.lname'] . <br/>;
  39.  
  40. foreach ($row as $key => value){
  41.  
  42. echo "$key : $value <br/>";
  43.  
  44. }
  45. echo '<br/>';
  46. }
  47.  
  48. echo '<p>- Trying to echo the variable $a, defined in the php include: <br>';
  49. echo '<pre>$a is: ' . $a .'</pre></p>';
  50.  
  51.  
  52. echo '<p>- Calling the function hello(), defined in the php include: </p>';
  53.  
  54.  
  55.  
  56. hello('admin');
  57.  
  58.  
  59.  
  60. // include some html
  61. include 'html_include.php';
  62.  
  63.  
  64.  
  65. ?>
  66. <h3> this is in the body of the main file</h3>
  67.  
  68. <blockquote>
  69. <h4>From the manual re. include() :</h4>
  70. <p>'When a file is included, the code it contains inherits
  71. <br/>the variable scope of the line on which the include occurs.
  72.  
  73. <br/><br/>Any <b>variables</b> available at that line in the calling file will be available <br/>
  74. within the called file, from that point forward.
  75.  
  76. <br/><br/>However, all <b>functions and classes</b> defined in the included file have the global scope.'*** <br/><br/>[*** but only after the line on which they're included]</p>
  77.  
  78. <p>Try moving the php inculde around to see how it affects the scope of '$a' and hello()</p>
  79.  
  80. </blockquote>
  81.  
  82.  
  83. </div>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement