Is it possible to do a query like I described in the title? I have two tables with different types of columns, nothing similar between them. What I want to do is join them together and display them in reversing order starting with the earliest but limiting to 5 per page. The way I'm getting the number of items is like this:
$limit = 5;
$page = 1;
if(isset($_GET['pn'])) {
$page = $_GET['pn'];
$lim = ($page-1)*$limit;
}else{
$lim = ($page-1)*$limit;
}
$l = mysqli_query($mysqli_connect, "SELECT id FROM table1");
$s = mysqli_query($mysqli_connect, "SELECT id FROM table2");
$r = mysqli_num_rows($l) + mysqli_num_rows($s);
Then I'm just adding the page number in the URL if the user clicks next. Right now to get the query from one table I'm doing this:
$sql = mysqli_query($mysqli_connect, "SELECT * FROM table1 ORDER BY dateadded desc LIMIT $lim, $limit");
I need help constructing a query that will select both tables...and how to keep track of which rows were already added using the LIMIT
?
UPDATE:
$sql = mysqli_query($mysqli_connect, "SELECT id FROM (SELECT id, dateadded FROM table1 UNION SELECT id, dateadded FROM table2) ORDER BY dateadded LIMIT $lim, $limit");
$num_rows = mysqli_num_rows($sql);
echo $num_rows;
I get a warning saying mysqli_num_rows() expects parameter 1 to be mysqli_result, boolean given in...
. Can't I see how many items were returned???