If I'm reading the comment at the of your second posted block of code right, it's immediately followed by the code in the first block, yes?
$var_array = explode("/",$REQUEST_URI);
$var = $var_array[2];
$subcats = mysql_query("SELECT * FROM table WHERE urlname='$var'");
$row = mysql_fetch_assoc($subcats);
$maincats = mysql_query("SELECT * FROM table GROUP BY main");
$row2 = mysql_fetch_assoc($maincats);
if ($var_array[3] != "")
{
$get = "SELECT * FROM table WHERE main='$row[main]' AND sub='" . takedash($var_array[3]) ."'";
$pquery = mysql_query($get);
$row3 = mysql_fetch_assoc($pquery);
for ($z=0; $z < mysql_num_rows($query); $z++)
{
// Select second database
mysql_select_db($dbname2, $connect);
$author = mysql_query("SELECT * FROM users WHERE id='$row3[author]'");
// Select normal database
mysql_select_db($dbname, $connect);
$authorrow = mysql_fetch_assoc($author);
$row3 = mysql_fetch_assoc($poemquery);
// Adjust time to correct format
$time = explode("-", $row3['date']);
echo "<a href='http://www.url.com/cat/" . $row3['id'] . "'>" . $row3['title'] . "</a><br>";
echo "By " . $authorrow['username'] . "<br>";
echo "Date added: ". $time[2] . "-" . $time[1] . "-" . $time[0] . "<br>";
If that is the case, the data you put into $row3 from the first database is never used before it gets destroyed by the data you're putting into the variable from the second database.
My preferred method would be to put all the results from both databases into a single array, and then after that go through the array to list its contents.
$results = array();
if($var_result[3]!='')
{
...$results[] = mysql_fetch_assoc(...);
for(...)
{
....$results[] = mysql_fetch_assoc(...);
}
foreach($results as $result)
{
format time and do echoes (using $result instead of $row3)
}