Jump to content

Recommended Posts

So I want to create a table with php and html that outputs a 10x10 table with numbers from 0 to 99 and differentiating prime numbers:

The problem is that every time it checks prime numbers from 0 to 99 it prints it in every '<tr>'. Ty in advance for the help!

It outputs a check of primer numbers from 0 to 99 every tr and i want it to be a single check from 0 to 99 using 10 tr

<html>

 <head>

    <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>

</head>

<body>

   <?php  

        echo "<table>";

        for($i=0; $i < 10; $i++){

            echo "<tr>";

            for($x=0; $x < 10; $x++){

                for($i=0;$i<=99;$i++){

                    $counter = 0; 

                    for($j=1;$j<=$i;$j++){

                        if($i % $j==0){

                            $counter++;

                        }

                    }

                    if($counter==2){

                        echo "<td style="background-color: yellow;">".$i."</td>";

                    }else{

                        echo "<td style="background-color: blue>".$i."</td>";

                    }

                }

            echo "</tr>";

            }

        }

        echo "</table>";

    ?>  

</body>

</html>

Link to comment
https://forums.phpfreaks.com/topic/311645-php-table-with-prime-numbers/
Share on other sites

Hints

  1. Put the numbers 0 - 99 in an array and use array_chunk() to get the rows.
  2. Loop through each chunk to get the cells in each row.
  3. when checking for N is prime, it is necessary only to check for factors <= sqrt(N)
Edited by Barand
This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  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.

×
×
  • 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.