Jump to content

2 questions: php to database and database loop


Hybride

Recommended Posts

Am trying to get a new layout working, the only problem is... connecting to the database.  Here's how it works: I have one page layout that has all of the variables on it. All other pages are only the variables set, which means they have to be set before sent off to the main page layout. The problem is, I can't connect to the database since the information in the main page is required beforehand... which I can't do. I am trying to avoid making the connection manually on every page or linking it during a separate file, if at all possible. Here's an example of what I mean:

 

<? include "include/incdb.hyb";

$metakey = "metastuff";
$metadesc = "metadescstuff.";
$metatitle = "title of the page";
$type = "index";
$submenuhl = "updates";

$subtxt = "text text text";
$subtxtq= mysql_query("SELECT * FROM updates ORDER BY id DESC LIMIT 7") OR die(mysql_error());
if ($subtxtq) {
	while ($row = mysql_fetch_array($subtxtq, MYSQL_ASSOC)) {
 		$subtxt = "<p><b> $row[date] :: </b><i> $row[title] </i> - $row[body] </p><br /><hr /><br />";
		}
	}
include "header.php";
?> 

 

And on the HTML, they are just the PHP page's variables within the layout (that way, I only update one page.) So in order for this to work, the variables have to be set before sending to the header, but the db connection requires the header to be set beforehand to work. Any way around this?

 

Also, if you noticed in the piece of code, I have a while loop going on. Am also trying to get each entry within the loop to be set to $subtxt. Is the only way to do it is with an array or some other way?

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.