Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- //connection parameters
- // include some php
- include 'php_include.php';
- echo '<div style="background:#ecc;border: 4px solid #dbb;">';
- function dbConnect(){
- $hostname = 'localhost';
- $username = 'tbcj857';
- $mysql_pass = 'm2d59';
- $database = 'tbcj857';
- $conx = mysql_connect ($hostname , $username, $mysql_pass)
- or die ("Can't connect to MySQL" . mysql_error() );
- mysql_select_db ($database)
- or die ("Can't select that database" . mysql_error() );
- return $conx;
- }
- dbConnect();
- $sql = "SELECT users.id, users.fname, users.lname, posts.post_title
- FROM users INNER JOIN posts
- ON users.id = posts.user_id";
- $result = mysql_query($sql) or die (mysql_error() );
- while ($row = mysql_fetch_assoc($result) ) {
- echo $row['posts.post_title'] . <br/> . $row['users.fname'] . $row['users.lname'] . <br/>;
- foreach ($row as $key => value){
- echo "$key : $value <br/>";
- }
- echo '<br/>';
- }
- echo '<p>- Trying to echo the variable $a, defined in the php include: <br>';
- echo '<pre>$a is: ' . $a .'</pre></p>';
- echo '<p>- Calling the function hello(), defined in the php include: </p>';
- hello('admin');
- // include some html
- include 'html_include.php';
- ?>
- <h3> this is in the body of the main file</h3>
- <blockquote>
- <h4>From the manual re. include() :</h4>
- <p>'When a file is included, the code it contains inherits
- <br/>the variable scope of the line on which the include occurs.
- <br/><br/>Any <b>variables</b> available at that line in the calling file will be available <br/>
- within the called file, from that point forward.
- <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>
- <p>Try moving the php inculde around to see how it affects the scope of '$a' and hello()</p>
- </blockquote>
- </div>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement