[Solved] Display results of a query before query itself


Using Javascript will likely work.

<div id="grandtotal">0.00</div>
<?php
$getinfo = mysql_query("SELECT * FROM sales");
while($rows = mysql_fetch_assoc($getinfo)){
    $price = $rows['price']; // I want this to be display on top of my page before this query
    $quantity = $rows['quantity']; // I want this to be display on top of my page before this query
    $total = $price * $quantity;
    $grand_total += $total;
}

?>
<script>
// I am using jQuery here. Traditional js will work
$('#grandtotal').html('<?php echo $grand_total; ?>');
</script>

9

solved Display results of a query before query itself