Currently my code has several querys, and they are together in the index file thus polluting the code. I would like to pass the query to another file and use only the $ variable in the index. It's possible? based on the snippet of my code how could I do that?
<?php
$sql = $pdo->prepare("SELECT ROUND(tbl1.diferenca/sum(buy)*100,2)AS roi from
home,(select sum(premio) - sum(buy) as diferenca from home ) as tbl1 WHERE
id_user = :id_user;");
$sql->bindValue(":id_user", $id);
$sql->execute();
if ($sql->rowCount() > 0) {
foreach ($sql->fetchAll() as $item) {
//valor
$roi = $item['roi'];
//condicional
if ($roi<0){
$cor='red';
}else{
$cor='green';
}
?>
<tr>
<th>ROI</th>
<td style='color:<?php echo $cor;?>'> R$ <?php echo $roi;?></td>
</tr>
<?php
}
}
?>