Using array_chunk() with the row count cut in half then rounded-up will ensure that the second column always has equal or one less row than the first column.
HTML tables should only be used to display "tabular" data. Since you are building two non-tabular lists, it would be more appropriate to employ other tags (several different tags may be appropriate).
Your question would be more complete if you stated why it doesn't "work".
I don't see anything wrong with the WHERE clause declarations (because the default glue is AND).
What does jump out at me is the fact that you are not expressing the columns which should be used to JOIN the two tables. This will be written with the ON keyword within the join() ...
I would advice you to use Aspose.PDF Cloud SDK for PHP to create PDF from HTML.
Here is a quick example:
// Initialize API
public $pdfApi = new PdfApi();
// Upload file to Aspose Cloud Storage
$fileName = "output.pdf";
$templateFile = "input.html";
// Convert file ...