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?

Link to comment
Share on other sites

but the db connection requires the header to be set beforehand to work. Any way around this?

 

You will need to reorganise your code more logically.

 

Is the only way to do it is with an array or some other way?

 

An array would be the best method.

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.