0

Hi, i wanna select some details from db and i wrote select query and i punted it in the while but, i wanna show the details in the columns instead of rows
is there any body to help me ????

$brush_price = 5; 
$counter = 10;

echo "<table border=\"1\" align=\"center\">";
echo "<tr><th>Quantity</th>";
echo "<th>Price</th></tr>";
while ( $counter <= 100 ) {
	echo "<tr><td>";
	echo $counter;
	echo "</td><td>";
	echo $brush_price * $counter;
	echo "</td></tr>";
	$counter = $counter + 10;
}
echo "</table>";

Quantity Price
10 50
20 100
30 150
40 200
50 250
60 300
70 350
80 400
90 450
100 500

Edited by Ezzaral: Added code tags. Please use them to format any code that you post.

2
Contributors
3
Replies
4
Views
5 Years
Discussion Span
Last Post by broj1
2

One way of doing it:

$brush_price = 5;
$counter = 10;

// row for quantities with heading in first cell
$qtyRow = '<tr><th>Quantity</th>';

// row for prices with heading in first cell
$priceRow = '<tr><th>Price</th>';

// add cells to each row
while ( $counter <= 100 ) {

    $qtyRow .= "<td>$counter</td>";

    $priceRow .= "<td>" . ($brush_price * $counter) . "</td>";

    $counter = $counter + 10;
}

// end of the rows
$qtyRow .= '</tr>';
$priceRow .= '</tr>';

// echo the table
echo "<table border=\"1\" align=\"center\">";
echo $qtyRow;
echo $priceRow;
echo "</table>";

Edited by broj1: n/a

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.