Jump to content
  • 0

Таблица умножения


romantik2011
 Share

Question

Подскажите, как закрасить вот так как на этой картинке? Не могу понять как.


<?php
$cols = 10;
$rows = 10;
$cols1 = 1;
echo '<h1><center>ТАБЛИЦА УМНОЖЕНИЯ</center></h1>';
echo '<table style="border:1px solid black; padding:10px; margin-left:300px;">';
while($cols1<$cols){
$rows1 = 1;
echo '<tr>';
while($rows1<$rows){
$rez = $cols1*$rows1;
echo '<td style="border:1px solid black; padding:20px;">'.$rez. ' '.' </td>';
$rows1++;
}
echo '<br />';
echo '</tr>';


$cols1++;
}
echo '</table>';
?>


BdbKMpjI.jpg

Edited by romantik2011
Link to comment
Share on other sites

12 answers to this question

Recommended Posts

  • 0

Не понял, а затруднения в чём ?


<?php
$cols = 10;
$rows = 10;
$cols1 = 1;
echo '<h1><center>ТАБЛИЦА УМНОЖЕНИЯ</center></h1>';
echo '<table style="border:1px solid black; padding:10px; margin-left:300px;">';
while($cols1<$cols){
$rows1 = 1;
echo '<tr>';
while($rows1<$rows){
$rez = $cols1*$rows1;

$color = 'white';
if ($cols1 == 1) {$color = 'yellow';}
if ($rows1 == 1) {$color = 'blue';}
if ($rows1 == 1 && $cols1 == 1) {$color = 'orange';}
echo '<td style="border:1px solid black; padding:20px; background-color: '.$color.'">'.$rez. ' '.' </td>';
$rows1++;
}
echo '<br />';
echo '</tr>';


$cols1++;
}
echo '</table>';
?>

Link to comment
Share on other sites

  • 0

Решил усовершенствовать таблицу умножения, написав функцию., вроде все окей, но никак не красит таблицу.


<?php

function table($cols,$rows,$color1,$color2,$color3){
echo '<div align="center"><h1 align="center">Таблица умножения</h1>
<table border=1>';
$color = ($cols == 1 && $rows == 1)?$color1:($cols == 1?$color2:($rows == 1?$color3:'white'));

for($i=1; $i<$cols; $i++){
echo '<tr align="center">';
for($j=1; $j<$rows; $j++){
$rez = $i * $j;
echo '<td style="background-color:".$color."; text-align:center;">'.$rez.'</td>';
}
echo '</tr>';
}

echo '</table></div>';
}

table(10,10,"blue","yellow","green");

?>

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Answer this question...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

 Share

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue. See more about our Guidelines and Privacy Policy