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

A) Take the code below and modify it to include a function. 1. take all the code

ID: 3734907 • Letter: A

Question

A) Take the code below and modify it to include a function.

1. take all the code you use to establish a DB connection
2. Wrap that code inside a function. Return variable is $cxn
3. Call the function right before the $result = line.
Continue with the rest of the code

?php

$host="student";
$user="user";
$password="pass";
$database="database";

$cxn=mysqli_connect($host,$user,$password,$database);
$sql="SELECT*FROM student";//category
$result=mysqli_query($cxn,$sql);

if($result==false)
{
   print("Error:".mysqli_error($cxn)."

");
}

else

{
   $sql="SELECT*FROM student";
  
   $result =mysqli_query($cxn,$sql);
  
   print("");
  
   for($i=0;$i    {
       print("");
       $row_array=mysqli_fetch_row($result);
       for($j=0;$j        {
           print("");
       }
}
}
?>

B) Take the function you created and move it to a file called MyLibrary.php

2. “Include” MyLibrary in your php code

3. Call the function from inside the code

studentID lastname quiz1 quiz2 quiz3 quiz4 quiz5 .$row_array[$j].

Explanation / Answer

replace $host, $user, $password, $database with your mysql connection params....

<?php

$host="student";

$user="user";

$password="pass";

$database="database";

$cxn=mysqli_connect($host,$user,$password,$database);

$sql="SELECT * FROM student";//category

$result=mysqli_query($cxn,$sql);

if($result==false)

{

print("Error:".mysqli_error($cxn)."");

}

else{

$sql="SELECT*FROM student";

$result =mysqli_query($cxn,$sql);

print("<table><tr><th>studentID</th><th>lastname</th><th>quiz1</th> <th>quiz2</th><th>quiz3</th><th>quiz4</th><th>quiz5</th></tr>");

for($i=0;$i<mysqli_num_rows($result);$i++){

print("<tr>");

$row_array=mysqli_fetch_row($result);

for($j=0;$j<7;$j++){

print("<td>".$row_array[$j]."</td>");

}

print("</tr>");

}

}

?>

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