John Smith John Smith - 9 days ago 5x
PHP Question

Inserting a table into a PHP while statement

I have created wrote PHP code which includes an array and a while statement. I need to put my results into a table like shown below. Tried many different ways but had no luck if anyone can point me in the right direction with this I would be very grateful. (New to PHP)

Table Example

<!DOCTYPE html>
<link type="text/css" rel="stylesheet" href="main.css"/>
echo "<b>Associative Arrays </b><br />";

$prices = array('t-shirt'=>'9.99','cap'=>'4.99','mug'=>'6.99');
echo "<br />";

echo "<h1>Loops</h1><br />";

echo "<b>While Looop</b><br />";
echo "<br />";

$shirt_price = $prices['t-shirt'];
$counter = 1;

while ($counter<=10)

{$price2 = ($counter*$shirt_price);

echo $counter . ' ' . $price2 . '<br />';




Try starting out with something simple like this

echo '<table>';
while ($counter<=10)
    $price2 = ($counter*$shirt_price);
    echo "<tr><td>$counter</td><td>$price2</td></tr>";
echo '</table>';

Once that is working you can look at things you can do to a table to make it look better etc.