You need to specify the correct connection to use in each query. How else would the code know which one to use?
__________________
If you are learning PHP, developing PHP code, or debugging PHP code, do yourself a favor and check your web server log for errors and/or turn on full PHP error reporting in php.ini or in a .htaccess file to get PHP to help you.
Open one of the db's.
Query results go into an array.
Close it.
Open the other db.
Query and process with the other array.
Close it.
If possible or necessary, cache the results into a file (like an XML file),
so the process above does not need to be executed too many times.
Tell us more about what you're doing.
Basically I am pulling content from one database but we also run a forum (located on a separate database) & I want to display the last post made on the forum on the website... so one database would provide content while the other would provide the latest post from the forum.
OK, an array would work, but also ...
Are there any RSS feeds created that would have the last post?
Perhaps your forum creates an RSS feed (an XML) file that you can utilize.
The only drawback may be that the RSS feed might be a "short version" of the post.
But otherwise, put the first database query into an array and you can find the last post.
OK, an array would work, but also ...
Are there any RSS feeds created that would have the last post?
Perhaps your forum creates an RSS feed (an XML) file that you can utilize.
The only drawback may be that the RSS feed might be a "short version" of the post.
But otherwise, put the first database query into an array and you can find the last post.
Sorry unfortunately I'm not getting this...
I'm currently opening the connection to the first database at the very top of the document, then data is pulled out at various places in the page (the last piece being at the footer).
The problem being that I cant close the connection at any time (until after the footer) but I want to display the forum posts before the footer, so when I try this it seems the databases clash!
Essentially, I can get the page to display data from one db OR the other... the only solution I can see would be to open and close a connection after every bit of data, but surely this would be a massive strain on the db and also would mean not using an include for the db credentials (which may be a security risk?)
I'm saying, before you even open the main page db, open the forum db and
query the last post, saving it in an array. Close it ...
Then, open your main page db and display everything as you normally do.
When you get to the the footer, you have the array all ready to be used.
Use the array contents to display the last forum post.
I'm saying, before you even open the main page db, open the forum db and
query the last post, saving it in an array. Close it ...
Then, open your main page db and display everything as you normally do.
When you get to the the footer, you have the array all ready to be used.
Use the array contents to display the last forum post.
Hey thanks,
Finally got it, sorry for being so slow! PHP is a new quantity to me:
For any other newbies experiencing the same problems, the final code was:
PHP Code:
<?php
// connection to the forum database
$connection = mysql_connect("host", "user", "pass") or die (mysql_error());
$db = mysql_select_db("databasename", $connection) or die (mysql_error());
// post query
$query = "SELECT * FROM table ORDER BY post_id DESC LIMIT 1";
$result = mysql_query($query) or die (mysql_error());
$row = mysql_fetch_array($result);
mysql_close();
// connection to main database
include ("connect.php");
?>
And in the main content:
PHP Code:
<?php
// show the last post from the forum
echo $row['post_subject'];
?>