Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Using WebMatrix. choose either empty PHP website or empty HTML website as the te

ID: 3572414 • Letter: U

Question

Using WebMatrix. choose either empty PHP website or empty HTML website as the template to create a PHP-enabled website that is made of indcx.php and proccss.php. indcx.php: This file collects user input with a form and sends the data to proccss.php. The form should have ten textboxes in a vertical order at top. Below these textboxes, two radio buttons specifying sort options should be placed above the submit button. At minimum, ten textboxes and corresponding labels should be placed in a table with border as shown below. proccss.php: This file first takes 10 numbers from indcx.php, sort them according to the sorting option specified and displays them in a vertical line as shown below. The sorting MUST be implemented using your own PHP code by adopting simple sorting algorithm like bubble sort. Using PHP library sorting function without your own code will cause 30 points deduction.

Explanation / Answer

index.php code :

<!DOCTYPE html>
<html>
<body>
<form action="process.php" method="post">
<p>
   Number 1 : <input type="text" name="numbers[]" /><br/>
   Number 2 : <input type="text" name="numbers[]" /><br/>
   Number 3 : <input type="text" name="numbers[]" /><br/>
   Number 4 : <input type="text" name="numbers[]" /><br/>
   Number 5 : <input type="text" name="numbers[]" /><br/>
   Number 6 : <input type="text" name="numbers[]" /><br/>
   Number 7 : <input type="text" name="numbers[]" /><br/>
   Number 8 : <input type="text" name="numbers[]" /><br/>
   Number 9 : <input type="text" name="numbers[]" /><br/>
   Number 10 : <input type="text" name="numbers[]" /><br/>
<p>
<br/>
<input type="radio" name="Order" value="Ascending" checked="checked" /> Ascending<br/>
<input type="radio" name="Order" value="Descending" /> Descending

<p><input type="submit" value="Submit"></p>
</form>
</body>
</html>

process.php code :

<?php
$order= $_POST['Order'];
$numbers = $_POST['numbers'];

// This function sorts using bubble sort. Breaks the loop array gets sorted early than max loops needed.

function sortNumbers($order,$numbers)
{
for($y=0;$y<10;$y++)
   {
       $isChanged = false;
       for($x=0;$x<9;$x++)
       {
               if(($numbers[$x] > $numbers[$x+1] && $order=='Ascending') || ($numbers[$x] < $numbers[$x+1] && $order=='Descending'))
               {
                   $temp=$numbers[$x+1];
                   $numbers[$x+1]=$numbers[$x];
                   $numbers[$x]=$temp;
                   $isChanged=true;              
               }         
       }
       if(!$isChanged)
       {
           break;
       }
   }
     
echo "10 input numbers sorted in ",$order," order","<br/>";
return $numbers;
}

function display($numbers)
{
   for($x=0;$x<10;$x++)
   {
       echo $numbers[$x];
       echo "<br/>";
   }
  
}
$numbers = sortNumbers($order,$numbers);
display($numbers);
?>

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote