John Davidson

Complete the information of a table using php to achieve a specific number

0 comments
Message:


I am designing a calendar using PHP, and I want to fill in the lines until I get to number 31. But this does not happen by changing the condition. How can I do this?


<body>
<table border="1">
<tbody>
<?php

$day=array("sat","sun","mon","tue","wed","thu","fri");

echo('<th>'.$day[0].'</th>');
echo('<th>'.$day[1].'</th>');
echo('<th>'.$day[2].'</th>');
echo('<th>'.$day[3].'</th>');
echo('<th>'.$day[4].'</th>');
echo('<th>'.$day[5].'</th>');
echo('<th>'.$day[6].'</th>');

for($i=1;$i<=31;$i){
echo("<tr>");
echo('<td>'.$i++.'</td>');
echo('<td>'.$i++.'</td>');
echo('<td>'.$i++.'</td>');
echo('<td>'.$i++.'</td>');
echo('<td>'.$i++.'</td>');
echo('<td>'.$i++.'</td>');
echo('<td>'.$i++.'</td>');
echo("</tr>");

}

?>
</tbody>
</table>

</body>



My Answer:
To achieve the specific number 31 in the calendar, you need to modify the for loop condition in your PHP code. Currently, you are incrementing the value of $i multiple times within each iteration of the loop, which is causing the loop to run indefinitely.

You can update your for loop condition to check if $i is less than or equal to 31 before incrementing it. Here is the updated code:

php
for($i=1;$i<=31;$i++){
echo("");
echo(''.$i.'');
echo(''.$i++.'');
echo(''.$i++.'');
echo(''.$i++.'');
echo(''.$i++.'');
echo(''.$i++.'');
echo(''.$i++.'');
echo("");
}


With this change, the for loop will run until $i reaches the number 31, and the calendar will be filled with the numbers from 1 to 31.

Rate this post

4 of 5 based on 5938 votes

Comments




© 2024 Hayatsk.info - Personal Blogs Platform. All Rights Reserved.
Create blog  |  Privacy Policy  |  Terms & Conditions  |  Contact Us