user1241886
user1241886

Reputation:

how to print this result using PHP

How to print this result using this code i didn't recognize myself what am i doing wrong can you please help me out

<?php
$brush_price = 5;

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

OUTPUT:-

Quantity Price
10        50
20        100
30        150

Upvotes: 1

Views: 174

Answers (4)

Naveen Kumar
Naveen Kumar

Reputation: 4601

Hope this helps

$brush_price = 5;
echo "<table border=\"1\" align=\"center\">";
echo "<tr><th>Quantity</th>";
echo "<th>Price</th></tr>";

for ( $count = 1, $counter=10; $count <= 10; $count++,$counter += 10) {
    echo "<tr><td>";
    echo $count;
    echo "</td><td>";
    echo $brush_price * $counter;
    echo "</td></tr>";
}
echo "</table>";    

Upvotes: 0

Ferdinand Liu
Ferdinand Liu

Reputation: 334

Your PHP code (you put wrong tag, it should be PHP):

for ( $counter++ = 10; $counter <= 100; $counter += 10)

It seems that you are intended to initialize $counter variable to some initial value (0, perhaps?) $counter++ means $counter = $counter + 1, it's an expression. You can't assign value to expression, it will throw invalid left side assignment error.

Try change to following code...

for ( $counter = 10; $counter <= 100; $counter += 10)

Javascript Equivalent:

var brush_price=5;
document.write('<table border="1" align="center"><tr><th>Quantity</th><th>Price</th></tr>');
for(var counter=0; counter <= 100; counter+=10){
  document.write('<tr><td>'+counter+'</td></td>'+(counter*brush_price)+'</td></tr>');
}
document.write('</table>');

Upvotes: 0

hotS85
hotS85

Reputation: 1036

Here you go: Same output, written in Javascript. Just put it in your html file.

var brush_price = 5;

document.write("<table border='1' align='center'>");
document.write("<tr><th>Quantity</th><th>Price</th></tr>");

for(var counter = 10; counter <= 100; counter += 10){
    document.write("<tr><td>" + counter + "</td><td>" + (counter * brush_price) + "</td></tr>");
}

document.write("</table>");

Upvotes: 0

skipZero
skipZero

Reputation: 169

I think you want something like this:

for ( $counter = 10; $counter <= 100; $counter += 10)

Upvotes: 1

Related Questions