I am aiming to insert the respective learning style into the database if the echo statement has been triggered by the if statement. The DB columns are as follows: studentNumber, dimension1, dimension2, dimension3, dimension4. Any feedback would be appreciated. Trialing 'mildly active' hence the statement only being present at that stage of the code.
<?php
$active =0;
$reflective=0;
$sensing=0;
$intuitive=0;
$visual=0;
$verbal=0;
$sequential=0;
$global=0;
$mildlyActive = "Mildly Active";
$moderatelyActive = "Moderately Active";
$stronglyActive = "Strongly Active";
$mildlyReflective = "Mildly Reflective";
$moderatelyReflective = "Moderately Reflective";
$stronglyReflective = "Strongly Reflective";
if(isset($_POST['submit'])){
foreach($_POST as $key=>$value){
if($key != "submit"){
$dbQuery1 = $db->prepare("select * FROM answer WHERE answerID = '".$value."'");
$dbQuery1-> execute();
while ($dbRow = $dbQuery1->fetch (PDO::FETCH_ASSOC)){
$answerTypeID=$dbRow["answerTypeID"];
$dbQuery2 = $db->prepare("select * FROM answerType WHERE answerTypeID = '".$answerTypeID."'");
$dbQuery2-> execute();
while ($dbRow2=$dbQuery2->fetch()){
$answerType=$dbRow2["answerType"];
//echo $answerType;
if ($answerType=='active'){
$active++;
}
if ($answerType=='reflective'){
$reflective++;
}
if ($answerType=='sensing'){
$sensing++;
}
if ($answerType=='intuitive'){
$intuitive++;
}
if ($answerType=='visual'){
$visual++;
}
if ($answerType=='verbal'){
$verbal++;
}
if ($answerType=='sequential'){
$sequential++;
}
if ($answerType=='global'){
$global++;
}
}
}
$dbQuery=$db->prepare("INSERT INTO `userResponse` VALUES (:studentID, :questionID, :answerID)");
$dbParams=array('studentID'=>$_SESSION["currentUser"], 'questionID'=>$key, 'answerID'=>$value);
$dbQuery->execute($dbParams);
}
}
}
if ($active>$reflective){
$total = $active - $reflective;
if ($total == 1){
echo "Mildly active";
$dbQuery=$db->prepare("INSERT INTO indexLearningStyle (dimension1) VALUE (:mildlyActive)");
}
if ($total == 2){
echo "Mildly active";
$dbQuery=$db->prepare("INSERT INTO indexLearningStyle (dimension1) VALUE (:mildlyActive)");
}
if($total == 3){
echo "Moderately active";
}
if($total == 4){
echo "Moderately active";
}
if ($total == 5){
echo "Strongly active";
}
}
else {
$total = $reflective - $active;
if ($total == 1){
echo "Mildly reflective";
}
if ($total == 2){
echo "Mildly reflective";
}
if ($total == 3){
echo "Moderately reflective";
}
if ($total == 4){
echo "Moderately reflective";
}
if ($total == 5){
echo "Strongly reflective";
}
}
if ($sensing>$intuitive){
$total = $sensing - $intuitive;
if ($total == 1){
echo "Mildly sensing";
}
if ($total == 2){
echo "Mildly sensing";
}
if($total == 3){
echo "Moderately sensing";
}
if($total == 4){
echo "Moderately sensing";
}
if ($total == 5){
echo "Strongly sensing";
}
}
else {
$total = $intuitive - $sensing;
if ($total == 1){
echo "Mildly intuitive";
}
if ($total == 2){
echo "Mildly intuitive";
}
if ($total == 3){
echo "Moderately intuitive";
}
if ($total == 4){
echo "Moderately intuitive";
}
if ($total == 5){
echo "Strongly intuitive";
}
}
if ($visual>$verbal){
$total = $visual - $verbal;
if ($total == 1){
echo "Mildly visual";
}
if ($total == 2){
echo "Mildly visual";
}
if($total == 3){
echo "Moderately visual";
}
if($total == 4){
echo "Moderately visual";
}
if ($total == 5){
echo "Strongly visual";
}
}
else {
$total = $verbal - $visual;
if ($total == 1){
echo "Mildly verbal";
}
if ($total == 2){
echo "Mildly verbal";
}
if ($total == 3){
echo "Moderately verbal";
}
if ($total == 4){
echo "Moderately verbal";
}
if ($total == 5){
echo "Strongly verbal";
}
}
if ($sequential>$global){
$total = $sequential - $global;
if ($total == 1){
echo "Mildly sequential";
}
if ($total == 2){
echo "Mildly sequential";
}
if($total == 3){
echo "Moderately sequential";
}
if($total == 4){
echo "Moderately sequential";
}
if ($total == 5){
echo "Strongly sequential";
}
}
else {
$total = $global - $sequential;
if ($total == 1){
echo "Mildly global";
}
if ($total == 2){
echo "Mildly global";
}
if ($total == 3){
echo "Moderately global";
}
if ($total == 4){
echo "Moderately global";
}
if ($total == 5){
echo "Strongly global";
}
}
?>
Related
Someone please help me to create a two triangle patter using PHP. I'm already code but the output didn't as expected below.
expected output
My code:
function generatePattern($num) {
for ($id1 = 0; $id1 <= $num; $id1 = $id1 + 1) {
for ($id2 = $num; $id2 >= $id1; $id2 = $id2 - 1) {
print(' ');
}
for ($id3 = 1; $id3 <= $id1; $id3 = $id3 + 1) {
if ($id3 % 4 == 3) {
echo "o";
} else if ($id3 % 2 == 1) {
echo "x";
} else {
echo " ";
}
}
echo "\n";
}
for ($id1 = 0; $id1 <= $num-1; $id1 = $id1 + 1) {
echo str_repeat(' ', $num - 1);
for($id3 = $num-1; $id3 >= $id1; $id3 = $id3 - 1){
if ($id3 % 4 == 3) {
echo "o";
} else if ($id3 % 2 == 1) {
if ($id1 % 4 == 3) {
echo "o";
} else if ($id1 % 2 == 0) {
echo " ";
} else if ($id1 % 2 == 1) {
echo "x";
} else {
echo "x";
}
} else if ($id3 == $id1){
echo "x";
} else {
echo " ";
}
}
echo "\n";
}
}
generatePattern(4);
And my current output like this (the bottom triangle still messed up)
output
Do the required changes for space between o and x
function generatePattern($num) {
if($num % 2 == 0)
{
$num1 = $num + 1;
}else{
$num1 = $num;
$num = $num - 1;
}
for ($id1 = 1; $id1 <= $num; $id1++) {
for ($id2 = $num; $id2 >= $id1; $id2--) {
print(' ');
}
for ($id3 = 1; $id3 <= $id1; $id3++) {
if ($id3 % 4 == 3) {
echo "o";
} else if ($id3 % 2 == 1) {
echo "x";
} else {
echo " ";
}
}
echo "\n";
}
$str = str_repeat('x o ', ceil(($num1*2)/4));
echo substr($str, 0, $num1*2);
echo "\n";
$j = $num;
for($id1 = $num; $id1 >=1; $id1 = $id1 - 2)
{
for($id2 = 2; $id2 >= 1; $id2--)
{
if($j % 2 == 0)
{
$pattern = [' ', 'x', ' ', 'o',];
}else{
$pattern = [' ', 'o', ' ', 'x',];
}
echo str_repeat(' ', ($id2%2 == 0) ? $num: $num - 1);
$design = implode('', $pattern);
do{
$design .= implode('', $pattern);
}while(strlen($design) < $id1);
echo substr($design, 0, $id1);
echo "\n";
}
$j--;
}
}
generatePattern(14);
I have a web application that I'm rebuilding in Laravel for a cleaning company.
1) I pass in the paramaters to the URL route
http://127.0.0.1:8000/book?bed_range=1&bath_range=1&percentage_range=0&duration_range=
2) It does calculations:
$bedroomCostFactor = [0, 30, 60, 90, 120, 150];
$bathroomCostFactor = [0, 20, 40, 60, 80, 100];
$percentageFactor = [0, 5, 15, 10, 20];
if (isset($bed_range) && !empty($bed_range)) {
if ($bed_range == 1) {
$bed_cost = $bedroomCostFactor[0];
} else if ($bed_range == 2){
$bed_cost = $bedroomCostFactor[1];
} else if ($bed_range == 3){
$bed_cost = $bedroomCostFactor[2];
} else if ($bed_range == 4){
$bed_cost = $bedroomCostFactor[3];
} else if ($bed_range == 5){
$bed_cost = $bedroomCostFactor[4];
} else if ($bed_range == 6){
$bed_cost = $bedroomCostFactor[5];
}
}
if(isset($bath_range) && !empty($bath_range)) {
if ($bath_range == 1) {
$bath_cost = $bathroomCostFactor[0];
} else if ($bath_range == 2){
$bath_cost = $bathroomCostFactor[1];
} else if ($bath_range == 3){
$bath_cost = $bathroomCostFactor[2];
} else if ($bath_range == 4){
$bath_cost = $bathroomCostFactor[3];
} else if ($bath_range == 5){
$bath_cost = $bathroomCostFactor[4];
} else if ($bath_range == 6){
$bath_cost = $bathroomCostFactor[5];
}
}
if(isset($percentage_range) && !empty($percentage_range)) {
if ($percentage_range == 0) {
$percentage_cost = $percentageFactor[0];
} else if ($percentage_range == 5){
$percentage_cost = $percentageFactor[1];
} else if ($percentage_range == 15){
$percentage_cost = $percentageFactor[2];
} else if ($percentage_range == 10){
$percentage_cost = $percentageFactor[3];
} else if ($percentage_range == 20){
$percentage_cost = $percentageFactor[4];
}
}
$subtotal = "100.00";
$tax = number_format($subtotal * .0725, 2);
$total = $subtotal + $tax;
$discount = number_format(($subtotal * $percentage_cost) / 100, 2);
For some reason, when I migrate the code to Laravel, it no longer works and it starts saying variables like $discount and $percentage_cost are undefined.
In my previous application the calculations run just fine like you'd expect. Why isn't it working in Laravel?
I had to remove the if condition
if(isset($percentage_range) && !empty($percentage_range)) {
Help me, i was writing my code, all done succesfully but my problem is when the "..." (separator) for my curerent page and last page showed after the last page, not between my current page and my last page
how can that possible ?
this is my script for showing the page :
<?php
$paging2 = mysqli_query($koneksi,"select * from laporan where seksi='{$seksi}'");
$jmldata = mysqli_num_rows($paging2);
$jmlhalaman = ceil($jmldata/$batas);
echo "<ul class='pagination'>";
if ($halaman !== 1){
echo "<li><a href='index.php?load=table_laporan&halaman=1'>First</a></li>";
}
if ($halaman > 1){
echo "<li><a href='index.php?load=table_laporan&halaman=".($halaman-1)."'>Previous</a></li>";
}
for($i =1; $i <= $jmlhalaman; $i++){
if ((($i >= $halaman - 3) && ($i <= $halaman + 3)) || ($i == 1) || ($i ==$jmlhalaman))
{
if ($i == $halaman){
$class="active";
} else{
$class="disable";
} //echo "<b>$i</b>";
echo "<li class='$class'>".$i."<span class='sr-only'>(current)</span></li>";
if($i==$jmlhalaman && $halaman <= $jmlhalaman-5) echo "<li><a>...</a></li>";
if($i==1 && $halaman >= 6) echo "<li><a>...</a></li>";
}
}
if ($halaman >= 1){
echo "<li><a href=index.php?load=table_laporan&halaman=". ($halaman+1)."'>Next</a></li>";
} if ($halaman >= 1){
echo "<li><a href='index.php?load=table_laporan&halaman=". ($jmlhalaman)."'>Last</a></li>";
}
echo "</ul>";
echo "<p>Total Data : <b>$jmldata</b> Data</p>";
?>
My timestamp code worked well before i put it in a function.. Get this parse error on line 55, ive marked the line number with "// LINE 55", cant figure it out :(
Here's my error:
Parse error: syntax error, unexpected '.' in C:\wamp\www\flueforumdk\config.php on line 55
Here's the calling of the function:
$GET_UNIX_STAMP_FROM_DB = $art[tidspunkt];
$UNIX_TIME_SECONDS = $GET_UNIX_STAMP_FROM_DB;
echo timestamp_converter($UNIX_TIME_SECONDS);
Here's my function code:
## TIMESTAMP CONVERTER FUNCTION
function timestamp_converter($UNIX_TIME_SECONDS){
// UDREGNING FRA UNIX TIME
$tid = time() - $UNIX_TIME_SECONDS;
$timer = floor($tid/3600);
$minutter = floor($tid/60);
$dage = floor($timer / 24);
$uge = floor($dage / 7);
$month = floor($dage / 30.5);
$aar = floor($dage / 365);
if($tid < 60){
echo"<b>$tid</b> sekunder";
} elseif ($tid > 60){
echo"";
}
if($minutter == 0){
echo"";
} elseif ($minutter < 60){
if($minutter == 1){
echo"<b>$minutter</b> minut";
}else{
echo"<b>$minutter</b> minutter";
}
}
if($timer == 0){
echo"";
} elseif ($timer < 24){
if($timer == 1){
echo"<b>$timer</b> time";
}else{
echo"<b>$timer</b> timer";
}
}
//LINE 55 if($dage == 0){
echo"";
} elseif ($dage < 7){
if($dage == 1){
echo"<b>$dage</b> dag";
}else{
echo"<b>$dage</b> dage";
}
}
if($uge == 0){
echo"";
} elseif ($uge < 4){
if($uge == 1){
echo"<b>$uge</b> uge";
}else{
echo"<b>$uge</b> uger";
}
}
if($month == 0){
echo"";
} elseif ($month < 12){
if($month == 1){
echo"<b>$month</b> måned";
}else{
echo"<b>$month</b> måneder";
}
}
if($aar == 0){
echo"";
} elseif ($aar > 0){
if($aar == 1){
echo"<b>$aar</b> år";
}else{
echo"<b>$aar</b> år";
}
}
}
I'm new to PHP and trying to create the following whilst minimizing the amount of code needed. PHP should show a list of 100 then display if the number is / by 3, 5 or 3 and 5. If not by any then show nothing.
This is what I've got so far, but any help would be great since not sure about the / by 3 and 5 bit as you can see below.
<?php $var = range(0, 100); ?>
<table>
<?php foreach ($var as &$number) {
echo " <tr>
<td>$number</td>
<td>";
if($number % 3 == 0) {
echo "BY3";
} elseif ($number % 5 == 0) {
echo "BY5";
} elseif ($number % 3 and 5 == 0) {
echo "BY3 AND 5";
}
echo "</td></tr>";
}
?>
</table>
Thanks
Nope... you should check first if it's divisble for 15 (3x5) (or 3 and 5) and after you can do other checks:
if($number % 15 == 0) {
echo "BY3 AND 5";
} elseif ($number % 5 == 0) {
echo "BY5";
} elseif ($number % 3 == 0) {
echo "BY3";
}
echo "</td></tr>";
?>
Because every number divisble for 15 is also divisble for 3 and 5. So your last check could never hit
if I'm reading your question correct then you are looking for :
if ($number % 3 == 0 && $number %5 == 0) {
echo "BY3 AND 5";
} elseif ($number % 3 == 0) {
echo "BY3";
} elseif ($number % 5 == 0) {
echo "BY5";
}
Alternative version :
echo ($number % 3 ? ($number % 5 ? "BY3 and 5" : "BY 3") : ($number % 5 ? "BY 5" : ""));
$num_count = 100;
$div_3 = "Divisible by 3";
$div_5 = "Divisible by 5";
$div_both = "Divisible by 3 and 5";
$not_div = "Not Divisible by 3 or 5";
for($i=0;$i<=$num_count;$i++)
{
switch($i)
{
case ($i%15==0):
echo $i." (".$div_both.")</br>";
break;
case ($i%3==0):
echo $i." (".$div_3.")</br>";
break;
case ($i%5==0):
echo $i." (".$div_5.")</br>";
break;
default:
echo $i."</br>";
break;
}
}
No need to do three if statements:
echo "<table border='1'>";
for ($i = 1; $i <= 100; $i++) {
echo "<tr><td>{$i}</td><td>";
if ($i % 3 == 0) echo "BY3 ";
if ($i % 5 == 0) echo "BY5";
echo "</td></tr>\n";
}
echo "</table>";
Update the code as given below
<?php $var = range(0, 100); ?>
<table>
<?php foreach ($var as &$number)
{
echo " <tr>
<td>$number</td>
<td>";
if($number % 3 == 0 && $number % 5 == 0)
{
echo "BY3 AND 5";
}
elseif ($number % 5 == 0)
{
echo "BY5";
}
elseif ($number % 3 == 0)
{
echo "BY3";
}
echo "</td></tr>";
}
?>
<?php
if($number % 5 == 0 && $number % 3 == 0) {
echo "BY3 AND 5";
} elseif ($number % 5 == 0) {
echo "BY5";
} elseif ($number % 3 == 0) {
echo "BY3";
} else{
echo "NOT BY3 OR 5";
}
?>
if($number % 15 == 0)
{
echo "Divisible by 3 and 5";
}
elseif ($number % 5 == 0)
{
echo "Divisible by 5";
}
elseif ($number % 3 == 0)
{
echo "Divisible by 3";
}
This is neater and completed to be run:
<?php
for ($i = 1; $i <= 100; $i++) {
if ($i % 15 == 0)
{
echo"Divisible by 3 and 5</br>";
}
elseif ($i%3==0)
{
echo"Divisible by 3</br>";
}
elseif ($i%5==0)
{
echo"Divisible by 5</br>";
}
else
{
echo $i,"</br>";
}
}
?>
<?php
for ($i = 1; $i <= 100; $i++) {
if ($i % 15 == 0) echo "This Number is Divisible by 3 and 5<br>";
else if ($i % 3 == 0) echo "This Number is Divisible by 3 only<br>";
else if ($i % 5 == 0) echo "This number is Divisible by 5 only<br>";
else{
echo "$i<br>";
}
}
?>