Question: I am aware of three ways of writing subqueries into a query.

* Normal subquery
* With clause
* Temporary table

Subqueries get extremely messy when there are multiples of them in a query, and especially when you have nested subqueries.

With clause is my preference, but you can only use the subqueries in a WITH clause in the select statement which directly follows the WITH clause (I believe).

Temporary tables are good, but they require quite a bit of over head in declaring the table.

Are there any other ways to refactor subqueries other than these?
And are there any trade offs between them that I haven't considered?

Answer: 
You need to use chaining.

```
$sub_1 = $data->find('td', 2)->find('td',1)->plaintext;
$sub_2 = $data->find('td', 2)->find('td',2)->plaintext;

```
The following code will convert each `div` into an array and then strip the HTML code.

```
$cell_three = $data->find('td', 2)->innertext;
$cell_three = explode("</div>", $cell_three);
$cell_three = array_map(function($v){
    return trim(strip_tags($v));
}, $cell_three);

```

Then you just loop over the array.

```
foreach($cell_three as $sub_cell){
    $sub_cell_one = $sub_cell->find('td', 1)->plaintext;
    $sub_cell_two = $sub_cell->find('td', 2)->plaintext;
}

```