Jump to content

Frames/header


ggkfc

Recommended Posts

i was wanting a like a top frame at the top of all my pages with links and read to use like a include or require once. however, because i have to access the database, would i be able to have it access the database in the header and pick stuff out in the bottom half of the page so i don't need to call on accessing the database on every page?

i have a forum and chat thing working well but without the header, but when i incorporate it with a include header.php

 

<?php

 

include "connect.php"; //mysql db connection here

include "header.php"; //mysql db connection here <--- added this

print "<link rel='stylesheet' href='style.css' type='text/css'>";

 

print "<A href='post.php'>New Topic</a><br>";

 

print "<table class='maintable'>";

 

print "<tr class='headline'><td width=50%>Topic</td><td width=20%>Topic Starter</td><td>Replies</td><td>Last replied time</td></tr>";

 

$getthreads="SELECT * from forumtutorial_posts where parentid='0' order by lastrepliedto DESC";

 

$getthreads2=mysql_query($getthreads) or die("Could not get threads");

 

while($getthreads3=mysql_fetch_array($getthreads2))

 

{

 

  $getthreads3[title]=strip_tags($getthreads3[title]);

 

  $getthreads3[author]=strip_tags($getthreads3[author]);

 

  print "<tr class='mainrow'><td><A href='message.php?id=$getthreads3[postid]'>$getthreads3[title]</a></td><td>$getthreads3[author]</td><td>$getthreads3[numreplies]</td><td>$getthreads3[showtime]<br>Last post by <b>$getthreads3[lastposter]</b></td></tr>";

 

}

 

print "</table>";

 

 

 

?> 

 

 

header =

<?

require_once 'connect.php';

$rs = query("select ID from users where ID = $user");

 

print date("H:i:s");

echo "  ID: $user<p>";

 

$rs = query("select * from users where ID = $user");

if ($row = mysql_fetch_assoc($rs)) {

  $cash = $row['Cash'];

  $name = $row['Name'];

  $bank = $row['Bank'];

  $token = $row['Token'];

} else {

  query("insert into users values (1)");

  $cash = 1;

}

echo "<p>Name: $name</p>";

echo "<p>Cash: $cash</p>";

echo "<p>Bank: $bank</p>";

echo "<p>Token: $token</p>";

 

?>

Link to comment
Share on other sites

i was wanting a like a top frame at the top of all my pages with links and read to use like a include or require once. however, because i have to access the database, would i be able to have it access the database in the header and pick stuff out in the bottom half of the page so i don't need to call on accessing the database on every page?

 

If you include in header, you don't need to include in other pages

When a file is included, the code it contains inherits the variable scope of the line on which the include occurs. Any variables available at that line in the calling file will be available within the called file, from that point forward. However, all functions and classes defined in the included file have the global scope.

 

Read here http://php.net/include

 

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.