I am trying to create an archives page for my blog, which is also still being built. I have three different MySQL tables I need to pull data from and 1 of them is unrelated from the other 2. I found a similar post here but seeing as how I am not very experienced with PHP I am not able to figure out how to convert that to what I need. I know this can easily be done by executing three different queries, but that will put an unnecessary load on the server and slow down page load times and everything else.
The 2 related categories are "blogs" and "categories" while the third is for a different application built into the blog called the "Brain Link"
Here are the two queries for the related tables:
$blogQuery = mysqli_query($link, "SELECT * FROM pub_blogs ORDER BY id DESC") or die ("Could not access DB: " . mysqli_error($link));
$row = mysqli_fetch_assoc($blogQuery);
$blogID = $link->real_escape_string($row['id']);
$title = $link->real_escape_string($row['title']);
$date = $link->real_escape_string($row['date']);
$category = $link->real_escape_string($row['category']);
$content = $link->real_escape_string($row['content']);
$blogID = stripslashes($blogID);
$title = stripslashes($title);
$date = stripslashes($date);
$category = stripslashes($category);
$content = stripslashes($content);
$catQuery = mysqli_query($link, "SELECT * FROM categories ORDER BY id DESC") or die ("Could not access DB: " . mysqli_error($link));
$row = mysqli_fetch_assoc($catQuery);
$catID = $link->real_escape_string($row['id']);
$catName = $link->real_escape_string($row['name']);
$description = $link->real_escape_string($row['descriptions']);
$catID = stripslashes($catID);
$catName = stripslashes($catName);
$description = stripslashes($description);
and here is the third unrelated query:
$brainQuery = mysqli_query($link, "SELECT * FROM brain_links ORDER BY id DESC") or die ("Could not access DB: " . mysqli_error($link));
$row = mysqli_fetch_assoc($brainQuery);
$brainID = $link->real_escape_string($row['id']);
$site_name = $link->real_escape_string($row['site_name']);
$site_url = $link->real_escape_string($row['site_url']);
$post_date = $link->real_escape_string($row['post_date']);
Is it possible to get data from all three of these with one query? If not can someone point me in the direction of somewhere that will tell me how to join the two related ones?
The blog table saves the category ID under the 'category' column to identify which category it belongs to
I appreciate any help or suggestions!