Code: Select all
<?php
//Connect to database
require("config.php");
//Query the database.
$query = "SELECT publication AS a, cartegory AS b, pub_time AS c FROM publications
UNION ALL
SELECT image AS a, image_cartegory AS b, image_time AS c FROM images ORDER BY c DESC";
$result = mysql_query($query);
if(!$result)
{
die('<p>Could not retrieve the data because: <b>' . mysql_error(). '</p>');
// Handle as desired
}else{ //If query is valid.
if(mysql_num_rows($result) > 0){
while ($row = mysql_fetch_assoc($result)){
echo "<p>".$row['a']."</p>";
}//End of while loop
}else{//If no rows were returned
echo "no rows returned";
}
}//Closes if query is valid statement.
?>
So far I have tried things like:
Code: Select all
//For the sake of simplicity, I won't include the html formatting here
while ($row = mysql_fetch_assoc($result)){ if ($row['a'] == $row['publication']){echo $row['publication'];} else{echo $row['image'];}
//OR
if ('a' == 'publication'){echo $row['a'];} elseif ('a' == 'image'){echo $row['a'];}