I am making a site for questions and answers in which few multiple choice questions will be displayed and the user would have to select radio buttons to answer the questions. After submitting, right and wrong answers would displayed and user would be given the option of seeing the correct answer.
In this page for seeing correct answers what I want to do is to show an image of tick mark for the correct option and a cross image for all other wrong options. But I am facing problems in writing the logic.
This is what I have done till now.
This page is for selecting which image is to be displayed
<?
session_start() ;
$wrong = array() ;
if( !empty($_SESSION['wrongAnswer'] ) ) {
$wrong = $_SESSION['wrongAnswer'] ;//wrongAnswer array has
//ids of wrongly answered
//questions
session_destroy() ;
}
if( !empty($_POST['wrongAnswer'] ) ) {
$wrong = $_POST['wrongAnswer'] ;
}
$i = 0 ;
$quesID = "";
$question = "" ;
require_once "connection.php";
foreach ($wrong as $n) {
<? $query = "SELECT * FROM answers WHERE question_id = '$n' " ;
if($result = $mysqli->query( $query ) ) {
if( $row = $result->fetch_object() ){
$answer = $row->answer ;
// $count++;
}
else
echo "Couldn't tally answer " . $mysqli->error ;
}
else
echo "Error executing query" . $mysqli->error ;
//<----- THIS IS WHERE THE WRONGLY ANSWERED QUESTIONS WILL BE DISPLAYED WITH IMAGES AS MENTIONED BEFORE ------>//
$query = "SELECT * FROM questions WHERE questionid='$n' " ;
$i ++ ;
if( $result = $mysqli->query( $query ) ) {
$count= $result->num_rows ;
echo '<form name = "checkans.php" action = "checkans.php" method = "POST" >' ;
$row = $result->fetch_object() ;
// $i++ ;
$quesID = $row->questionid ;
$question = $row->question ;
$quesID = $row->questionid ;
$query2 = "SELECT option1,option2,option3,option4 FROM options WHERE questionid='$quesID'" ;
if($result2 = $mysqli->query($query2) ) {
if($row2 = $result2->fetch_object() ) {
$option1 = $row2->option1 ;
$option2 = $row2->option2 ;
$option3 = $row2->option3 ;
$option4 = $row2->option4 ;
?>
<table border="0" cellpadding="0" cellspacing="0">
<? echo "<div id = $row->questionid name = boxs>" ; ?>
<th> <h2> <? echo $i .")" ; ?> </h2> </th>
<th> <h2> <?echo $row->question ;?> </h2> </th>
<tr> <input type="hidden" name="quesID[]" id="<? echo $quesID ; ?>" value="<? echo $quesID ; ?>">
<div id = "options">
<td>
<span id = "1">
<img id = "image" height="50px" width="50px">
</td>
<td>
<label>
<? echo $option1 ;?>
</label>
</td>
</span>
<td>
<span id = "2">
<img id = "image" height="50px" width="50px">
</td>
<td>
<label>
<? echo $option2 ;?>
</label>
</td>
</span>
<td>
<span id = "3">
<img id = "image" height="50px" width="50px">
</td>
<td>
<label>
<? echo $option3 ;?>
</label>
</td>
</span>
<td>
<span id = "4">
<img id = "image" height="50px" width="50px">
</td>
<td>
<label>
<? echo $option4 ;?>
</label>
</td>
</div>
</span>
</div>
</tr>
</table>
</section>
<?
}
else
echo "No options available for this question" ;
}
}
?>
<script type="text/javascript">
var i = 0
for(i=1; i <= 4; i++) {
var y = document.getElementById(i);
//alert(y.childNodes)
var x = document.getElementById("image");
if( y.id == (<?echo $answer ; ?>) ) {
x.src = "correct.png" ;
}
else
x.src = "wrong.jpg" ;
}
}
</script>
<?
}
?>
Thing wrong with my code is that it just displays image for only 1 question and that too with the wrong option.
Related
after enter 3 type of words (alphabetic numeric and alphanumeric in html file. on second page we need to create button and links which will take us to third page. if we click first button it should show us only alphabetic. second button should show only numeric.
someone please help!!
file second:
$sentence = isset($_GET["phrase"]) ? $_GET["phrase"] : $_GET["phrase"];
$w = transformer($sentence);
$sentence = isset($_GET["filter"]) ? $_GET["filter"] : $_GET["filter"];
$w = transformer($sentence);
?>
<table>
<tr>
<th>Word</th>
<th>Length</th>
<th>Type</th>
<tr><td>
<?php
for ($x = 0; $x < count($w); $x++) {
echo "$w[$x] <br>";
}
?> </td>
<td> <?php
for ($x = 0; $x < count($w); $x++) {
$length = strlen($w[$x]);
echo "$length <br>";
}
?>
</td>
<td> <?php
for ($x = 0; $x < count($w); $x++) {
if (ctype_alpha($w[$x])) {
echo "Alphabetic <br>";
} else if(ctype_digit($w[$x])) {
echo "Numeric <br>";
} else {
echo "Alphanumeric <br>";
}
}
?>
</td>
</tr>
</tr>
<?php
function transformer($words){
$w = explode(' ', $words);
return $w;
}
function validation($words){
if($words == null || $words == ""){
echo "Submission will not proceed";
return false;
}
else if(!is_numeric($words)){
echo "Submission will proceed";
return false;
}
return true;
}
?>
<form action="PhraseFilter.php" method="get">
<input type="hidden" name="phrase" value="<?php echo
$_POST["phrase"]?>"/>
<input type="hidden" name="filter" value="TBD"/>
<input type="submit" value="show alpha"
onclick="document.getElementById('filter').value = 'alphabetic';"/>
<input type="submit" value="Show number"
onclick="document.getElementById('filter').value = 'numeric';" />
</form>
</div>
</body>
Second file
$sentence = isset($_POST["phrase"]) ? $_POST["phrase"] : $_GET["phrase"];
$w = transformer($sentence);
$sentence = isset($_POST["filter"]) ? $_POST["filter"] : $_POST["filter"];
$w = transformer($sentence);
?>
<table>
<tr>
<th>Word</th>
<th>Length</th>
<th>Type</th>
<tr><td>
<?php
for ($x = 0; $x < count($w); $x++) {
echo "$w[$x] <br>";
}
?> </td>
<td> <?php
for ($x = 0; $x < count($w); $x++) {
$length = strlen($w[$x]);
echo "$length <br>";
}
?>
</td>
<td> <?php
//for ($x = 0; $x < count($w); $x++) {
if ((ctype_alpha(substr($w[$x])){
echo "Alphabetic <br>";
} else if(ctype_digit(substr($w[$x])) {
echo "Numeric <br>";
}
// }
?>
</td>
</tr></tr>
<?php
function transformer($words){
$w = explode(' ', $words);
return $w;
}
// Validations
function validation($words){
// Validation if Empty
if($words == null || $words == ""){
echo "Submission will not proceed";
return false;
}
// Validation if Valid Number
else if(!is_numeric($words)){
echo "Submission will proceed";
return false;
}
return true;
}
?>
<?php
?>
</div>
</body>
I'm trying to separate the data that I get here and trying to register it in the database.
I get the data with a form that looks like this.
var max_input_fields=10;
var delimiter='|';
function http( data, callback ){
var xhr=new XMLHttpRequest();
xhr.onreadystatechange=function(){
if( xhr.readyState==4 && xhr.status==200 ) callback.call( this, xhr.response );
};
xhr.open( 'POST', document.location.href, true );
xhr.send( data );
}
function cbhttp(r){
document.querySelectorAll('output')[0].innerHTML=r
}
function bindEvents(){
var oBttnAdd=document.getElementById('bttnadd');
var oBttnSub=document.getElementById('bttnsub');
var oForm=document.getElementById('dynelems');
var oParent=document.getElementById('loopdiv');
oBttnSub.onclick=function(e){
/* scan the form and get values from all elements ( including dynamcially added ) and submit the form via xhr */
var col=oForm.querySelectorAll('input[type="text"],textarea,select');
var data=new FormData();
data.append('delimiter',delimiter);
for( var n in col ) if( col[n] && col[n].nodeType==1 ) {
data.append( col[n].name, col[n].value.replace( delimiter, '' ) + delimiter );
}
http.call( this, data, cbhttp );
};
oBttnAdd.onclick=function(e){
/* Add new rows based upon selected option from dropdown menu */
var col=oParent.querySelectorAll('section[data-id]');
var length=col.length;
if( length < max_input_fields ){
var newid=parseInt( col[ length-1 ].dataset.id ) + 1;
var clone=oParent.childNodes[1].cloneNode( true );
clone.dataset.id=newid;
/* Set new name for the textarea */
clone.childNodes[3].childNodes[1].name='videolink'+newid;
oParent.appendChild( clone );
}
}
}
document.addEventListener('DOMContentLoaded', bindEvents,false);
<form action="adddilemman.php" id="dynelems" method="post" enctype="multipart/form-data">
<br>
<div id='loopdiv'>
<?php
/* Data-id is used by js to determine next suitable id */
echo "
<section data-id=1>
<h2>Dilemma</h2>
<div>Video länk:<br><textarea rows='1' cols='40' name='videolink1'></textarea></div>";
for( $i=1; $i <= 4; $i++ ){
/* Add four text fields and four select menus */
echo "
<div>
Answer: <input type='text' name='answer{$i}[]'/>
<select name='options{$i}[]'>";
/* Add options to each select menu */
for( $j=1; $j <= 10; $j++ ){
echo "<option value={$j}>{$j}";
}
/* Close each nested div & select menu */
echo "
</select>
</div>";
}
/* Close initial section */
echo "
</section>";
?>
</div>
<div class='input_fields_wrap'>
<div></div>
</div>
<input id='bttnadd' type='button' name='add_field_button' value='Lägg till fler svar'/>
<input id='bttnsub' type='submit' name='sub' value='Submit'/>
</form>
<output></output>
I'm using "adddilemman.php" to show the data just to see if its working and its working. But I have now idea how to register this data in the database. PS I want to register it in two different tables (textarea in a table and answers in another table)
<?php
if( $_SERVER['REQUEST_METHOD']=='POST' ){
ob_clean();
/* This is here only to simplify development and display here */
$delimiter=isset( $_POST['delimiter'] ) ? $_POST['delimiter'] : '|';
/* process form submission: for testing purposes just echo out data sent */
foreach( $_POST as $field => $value ) {
if( $field!='delimiter' ){
if( is_array( $value ) ) echo 'Array values: '.$field.'='.rtrim( str_replace( $delimiter, ',', implode( ' ', $value ) ), ',' ).'<br />';
else echo 'String value: '.$field.'='.trim( str_replace( $delimiter, '', $value ) ).'<br />';
}
}
exit();
}
?>
Any recommendations how I can separate this data and register it in the database?
You would want to setup the form like so:
<textarea rows='1' cols='40' name='videolink1'><?php echo isset($_POST['videolink1'])?$_POST['videolink1']:""; ?></textarea>
<?php
for( $i=1; $i < 5; $i++ ){
/* Add four text fields and four select menus */
?>
<div>
<label>Answer:</label>
<input type='text' name='answer[<?php echo $i; ?>]' value="<?php echo isset($answer[$i])?$answer[$i]:''; ?>" />
<select name='options[<?php echo $i; ?>]'>
<?php
for( $j=1; $j <= 10; $j++ ){
if($options[$i] == $j){
echo "\t\t\t\t\t<option selected='selected' value={$j}>{$j}</option>\r\n";
} else {
echo "\t\t\t\t\t<option value={$j}>{$j}</option>\r\n";
}
}
?>
</select>
</div>
<?php
}
?>
I would prepare the post data like so:
<?php
$vidlink = "";
$answers = array();
$options = array();
if(isset($_POST['sub'])){
$vidlink = htmlentities($_POST['videolink1']);
for($i=1;$i<=count($_POST['answer']);$i++){
$answer[$i] = $_POST['answer'][$i];
$options[$i] = $_POST['options'][$i];
}
}
?>
This will place the content of the answers and options in their own arrays but with the same indexes. You can loop and place them in the DB any way you like. Here is an example:
$con = mysqli_connect("localhost", "root", "", "wildfire");
if($con === false){
die("ERROR: Could not connect. " . mysqli_connect_error());
}
for($i=1;$i<=$count($answer);$i++){
if ($stmt = mysqli_prepare($con, "INSERT INTO answer_det ('aid', 'answer', 'points') VALUES (?, ?, ? )")) {
mysqli_stmt_bind_param($stmt, "isi", $i, $answer[$i], $options[$i]);
mysqli_stmt_execute($stmt);
}
}
Here is all the code I used for testing on phpfiddle.org:
<?php
$vidlink = "";
$answers = array();
$options = array();
if(isset($_POST['sub'])){
$vidlink = htmlentities($_POST['videolink1']);
for($i=1;$i<=count($_POST['answer']);$i++){
$answer[$i] = $_POST['answer'][$i];
$options[$i] = $_POST['options'][$i];
}
}
?>
<html>
<body>
<form action="<?php echo $_SERVER['PHP_SELF']; ?>" id="dynelems" method="post" enctype="multipart/form-data">
<div id='loopdiv'>
<section data-id=1>
<h2>
Dilemma
</h2>
<div>
Video länk:
<br />
<textarea rows='1' cols='40' name='videolink1'><?php echo isset($_POST['videolink1'])?$_POST['videolink1']:""; ?></textarea>
</div>
<?php
for( $i=1; $i < 5; $i++ ){
/* Add four text fields and four select menus */
?>
<div>
<label>Answer:</label>
<input type='text' name='answer[<?php echo $i; ?>]' value="<?php echo isset($answer[$i])?$answer[$i]:''; ?>" />
<select name='options[<?php echo $i; ?>]'>
<?php
for( $j=1; $j <= 10; $j++ ){
if($options[$i] == $j){
echo "\t\t\t\t\t<option selected='selected' value={$j}>{$j}</option>\r\n";
} else {
echo "\t\t\t\t\t<option value={$j}>{$j}</option>\r\n";
}
}
?>
</select>
</div>
<?php
}
?>
</section>
</div>
<div class='input_fields_wrap'>
<div>
</div>
</div>
<input id='bttnadd' type='button' name='add_field_button' value='Lägg till fler svar'/>
<input id='bttnsub' type='submit' name='sub' value='Submit'/>
</form>
<output>
<?php
if(isset($_POST['sub'])){
htmlentities(var_export($_POST));
var_export($answer);
var_export($options);
}
</output>
</html>
Here is an image of what I'm trying to accomplish -
Example of my Database Table -
My goal is to get a similar product to the product that is currently displaying without refreshing the page. I am trying to find similar products is by using check boxes.
I first got the id using $_GET['id'] which should be equal to one of the values in my table.
I then used PDO Fetch to get the product name, brand, quanity and price of that particular id and store it as a string.
What I need help with is using JQuery/AJAX to get the checkboxes that are checked and then send the information to a PHP file that would check if filter results match with any data from the table.
How can I do this?
This is my product.php file
<?php
require ('includes/db.php');
$id = $_GET['id']; //Getting the ID in URL. ex products.php?id=12
$stmt = $handler->prepare("SELECT * FROM products WHERE id = '$id' ");
$result = $stmt->execute(array());
$products = $stmt->fetch(PDO::FETCH_ASSOC);
$prod_name = $products['prod_name']; //Product Name
$brand = $products['brand']; //Product Brand
$quantity = $products['quantity']; //Product Quantity
$calories = $products['calories']; //Product Calories
$price = $products['price']; //Product Price
?>
<!DOCTYPE html>
<html>
<head>
<title><?php echo "$brand $prod_name"; ?></title>
</head>
<body>
<h1><?php echo $prod_name; ?></h1>
<br />
<p>Brand = <?php echo " $brand"; ?></p>
<p>Quantity = <?php echo " $quantity"; ?></p>
<p>Calories = <?php echo " $calories"; ?></p>
<p>Price = <?php echo " $price"; ?></p>
<br />
<p style="text-align: center;">Find Similar Products</p>
<form>
<div class="checkboxes">
<label>
<input name="brand" type="checkbox" value="<?php echo $brand; ?>">
<span>Brand</span> <!--Brand Checkbox-->
</label>
</div>
<div class="checkboxes">
<label>
<input name="quanitity" type="checkbox" value="<?php echo $quantity; ?>">
<span>Quantity</span> <!--Quantity Checkbox-->
</label>
</div>
<div class="checkboxes">
<label>
<input name="calories" type="checkbox" value="<?php echo $calories; ?>">
<span>Calories</span> <!--Calories Checkbox-->
</label>
</div>
<div class="checkboxes">
<label>
<input name="price" type="checkbox" value="<?php echo $price; ?>">
<span>Price</span> <!--Price Checkbox-->
</label>
</div>
</form>
</body>
</html>
I managed to solve this out, glad I didn't give up.
My product.php File
<?php
require ('/db.php');
$id = $_GET['id']; //Getting the ID in URL. ex products.php?id=12
$stmt = $handler->prepare("SELECT * FROM products WHERE id = '$id' ");
$result = $stmt->execute(array());
$products = $stmt->fetch(PDO::FETCH_ASSOC);
$prod_name = $products['prod_name']; //Product Name
$brand = $products['brand']; //Product Brand
$quantity = $products['quantity']; //Product Quantity
$calories = $products['calories']; //Product Calories
$price = $products['price']; //Product Price
?>
<!DOCTYPE html>
<html>
<head>
<title><?php echo "$brand $prod_name"; ?></title>
</head>
<body>
<h1><?php echo $prod_name; ?></h1>
<br />
<p>Brand = <?php echo " $brand"; ?></p>
<p>Quantity = <?php echo " $quantity"; ?></p>
<p>Calories = <?php echo " $calories"; ?></p>
<p>Price = <?php echo " $price"; ?></p>
<br />
<p style="text-align: center;">Find Similar Products</p>
<form method="post" action="">
<div class="checkboxes">
<label>
<input name="brand" type="checkbox" value="<?php echo $brand; ?>">
<span>Brand</span> <!--Brand Checkbox-->
</label>
</div>
<div class="checkboxes">
<label>
<input name="quanitity" type="checkbox" value="<?php echo $quantity; ?>">
<span>Quantity</span> <!--Quantity Checkbox-->
</label>
</div>
<div class="checkboxes">
<label>
<input name="calories" type="checkbox" value="<?php echo $calories; ?>">
<span>Calories</span> <!--Calories Checkbox-->
</label>
</div>
<div class="checkboxes">
<label>
<input name="price" type="checkbox" value="<?php echo $price; ?>">
<span>Price</span> <!--Price Checkbox-->
</label>
</div>
</form>
<div class="filter_container">
<div style="clear:both;"></div>
</div>
<script type="text/javascript" src="/js/filter.js"></script>
<input name="prod_name" value="<?php echo $prod_name ?>" style="display:none;"/>
<!--Hidden product name-->
</body>
</html>
Here is my JS File
$(document).ready(function() {
function showValues() {
var brand;
var quantity;
var calories;
var price;
//Gets product name
var prod_name = $('input[name="prod_name"]').val();
//Gets brand
if($('input[name="brand"]').is(':checked'))
{brand = $('input[name="brand"]').val();} else {brand = ""}
//Gets quantity
if($('input[name="quantity"]').is(':checked'))
{quantity = $('input[name="quantity"]').val();} else {quantity = ""}
//Gets calories
if($('input[name="calories"]').is(':checked'))
{calories = $('input[name="calories"]').val();} else {calories = ""}
//Gets price
if($('input[name="price"]').is(':checked'))
{price = $('input[name="price"]').val();} else {price = ""}
$.ajax({
type: "POST",
url: "/query.php",
data: {'brand':brand, 'quantity':quantity, 'calories':calories, 'prod_name':prod_name},
cache: false,
success: function(data){
$('.filter_container').html(data)
}
});
}
//Call function when checkbox is clicked
$("input[type='checkbox']").on( "click", showValues );
//Remove checked when checkbox is checked
$(".checkboxes").click(function(){
$(this).removeAttr('checked');
showValues();
});
});
Here is my PHP File
<?php
include('/db.php');
$prod_name = $_POST['prod_name'];
$Cbrand = $_POST['brand'];
$Cquantity = $_POST['quantity'];
$Ccalories = $_POST['calories'];
$Cprice = $_POST['price'];
if(!empty($Cbrand))
{
$data1 = "brand = '$Cbrand' AND";
}else{
$data1 = "";
}
if(!empty($Cquantity))
{
$data2 = "quantity = '$Cquantity' AND";
}else{
$data2 = "";
}
if(!empty($Ccalories))
{
$data3 = "calories = '$Ccalories' AND";
}else{
$data3 = "";
}
if(!empty($Cprice))
{
$data4 = "price = '$Cprice'";
}else{
$data4 = "";
}
$main_string = "WHERE $data1 $data2 $data3 $data4"; //All details
$stringAnd = "AND"; //And
$main_string = trim($main_string); //Remove whitespaces from the beginning and end of the main string
$endAnd = substr($main_string, -3); //Gets the AND at the end
if($stringAnd == $endAnd)
{
$main_string = substr($main_string, 0, -3);
}else if($main_string == "WHERE"){
$main_string = "";
}
else{
$main_string = "WHERE $data1 $data2 $data3 $data4";
}
if($main_string == ""){ //Doesn't show all the products
}else{
$sql = "SELECT COUNT(*) FROM products $main_string";
if ($res = $handler->query($sql)) {
/* Check the number of rows that match the SELECT statement */
if ($res->fetchColumn() > 0) {
$sql = "SELECT * FROM products $main_string";
foreach ($handler->query($sql) as $pro) {
if(($pro['prod_name'] == $prod_name) && ($res->fetchColumn() < 2))
{
//The product currently being displayed is blank when using the filter
}
else{
?>
<!------------------------------------------------------------------------------------------------------------------------------------------------->
<div class="form-result">
<td><?=strtoupper($pro['brand']) + " " + strtoupper($pro['prod_name']); ?></td>
</div>
<!------------------------------------------------------------------------------------------------------------------------------------------------->
<?php
}
}
} /* No rows matched -- do something else */
else {
?>
<div align="center"><h2 style="font-family:'Arial Black', Gadget, sans-serif;font-size:30px;color:#0099FF;">No Results with this filter</h2></div>
<?php
}
}
}
$handler = null;
$res = null;
?>
I am using Orangehrm 3.2.1(latest build). Below is the php code I am using to display a leave plan calendar for the employees employed with me since its too costly to buy from Orangehrm. When I run this script, I get screen on my browser which shows a part of the code....
".$seeDate.""; ?>
Month: Year:
".$i."
"; } ?> "; $even = 1; while ($row = mysql_fetch_array( $result ) ) { $employee_id = $row['employee_id']; $employee_num = $row['emp_number']; $employee_firstname = $row['emp_firstname']; $employee_lastname = $row['emp_lastname']; echo ""; if ( $even % 2) echo " "; else echo " "; $even++; // echo "$even $numDays
"; for ($i = 1; $i <= $numDays; $i++) { $day = checkDay($employee_num, $i, $month, $year); // echo "$employee_num, $i, $month, $year $day
"; switch ($day) { case 'holiday': echo " "; break; case 'weekend': echo " "; break; case 'absence_full': echo " "; break; case 'absence_partial_m': echo " "; break; case 'absence_partial_a': echo " "; break; default: echo " "; break; }//switch }//for echo ""; }//while ?>
The code which is seen on the screen is a part of my php script. Is there any modification that i need to carry out? I have played a lot around with it but don't seem to get it correct. The code as compared to orangehrm version 2.5 has been changed and they have been marked with // in the script below.
<?php
/*****************/
/* Configuration */
/*****************/
//Database information
$db_host = "localhost";
$db_user = "root";
$db_pwd = "";
$db_name = "main";
$db_port = 3306;
$logoLink = "orangehrm/symfony/web/webres_513fd0981da216.38969927/themes/default/images/login/logo.png";
/******************************/
/* DONT EDIT BELLOW THIS LINE */
/******************************/
//Year
if (isset($_GET['year']))
$year = $_GET['year'];
else
$year = date("Y");
//Month
if (isset($_GET['month']))
$month = $_GET['month'];
else
$month = date("m");
$date_aux = $year . "-" . $month;
$seeDate = date("Y-m", strtotime($date_aux));
/* Number of days in a month/Year */
function monthDays($month, $year) {
return date("t", strtotime($year . "-" . $month . "-01"));
}//
//admin get Years
function getYears($year) {
global $db_host, $db_user, $db_pwd, $db_name, $db_port;
if(!isset($year))
$year = date("Y");
// $sql = "SELECT DISTINCT(EXTRACT(Year FROM leave_date)) FROM hs_hr_leave WHERE 1 ORDER BY leave_date;";
$sql = "SELECT DISTINCT(EXTRACT(Year FROM date)) FROM ohrm_leave WHERE 1 ORDER BY date;";
// Make a MySQL Connection
mysql_connect($db_host, $db_user, $db_pwd) or die(mysql_error());
mysql_select_db($db_name) or die(mysql_error());
//Query
$result = mysql_query($sql) or die(mysql_error());
while ($row = mysql_fetch_array($result )) {
if ($row['(EXTRACT(Year FROM Date))'] == $year) {/*
echo "<option value=\"".$row['(EXTRACT(Year FROM leave_date))']."\" selected>".$row['(EXTRACT(Year FROM leave_date))']."</option><br>";*/
echo "<option value=\"".$row['(EXTRACT(Year FROM date))']."\" selected>".$row['(EXTRACT(Year FROM date))']."</option><br>";
} else {
// echo "<option value=\"".$row['(EXTRACT(Year FROM leave_date))']."\">".$row['(EXTRACT(Year FROM leave_date))']."</option><br>";
echo "<option value=\"".$row['(EXTRACT(Year FROM date))']."\">".$row['(EXTRACT(Year FROM date))']."</option><br>";
}
}
}//
function weekDay($date) {
$thisDay = date("D", strtotime($date));
return $thisDay;
}//
function checkDay($employee_id, $i, $month, $year) {
global $db_host, $db_user, $db_pwd, $db_name, $db_port;
$date = $year . "-" . $month . "-" . $i;
// $sql = "SELECT * FROM hs_hr_holidays WHERE date = '$date';";
$sql = "SELECT * FROM ohrm_holiday WHERE date = '$date';";
mysql_connect($db_host, $db_user, $db_pwd) or die(mysql_error());
mysql_select_db($db_name) or die(mysql_error());
$result = mysql_query($sql)or die(msysql_error());
$result_count = mysql_num_rows($result);
if ($result_count > 0)
return "holiday";
if( ( weekDay($date) == "Sat") || ( weekDay($date) == "Sun") ) {
return "weekend";
}
//Get Absences
// $sql = "SELECT leaves.*
// FROM `hs_hr_leave` AS leaves
// WHERE (leaves.employee_id = '$employee_id') AND (leaves.leave_date = '$date') AND (leaves.leave_status > 1)
// ORDER BY leaves.leave_date ASC;";
$sql = "SELECT leaves.*
FROM `ohrm_leave` AS leaves
WHERE (leaves.emp_number = '$employee_id') AND (leaves.date = '$date') AND (leaves.status > 1)
ORDER BY leaves.date ASC;";
mysql_connect($db_host, $db_user, $db_pwd) or die(mysql_error());
mysql_select_db($db_name) or die(mysql_error());
$result = mysql_query($sql)or die(mysql_error());
$result_count = mysql_num_rows($result);
if ( $result_count == 0 ) {
// echo "default<br>";
return "default";
} else {
while ($row = mysql_fetch_array( $result ) ) {
if ($row['leave_length_days'] < 1.0 ) {
if ( ($row['start_time'] >= "08:00:00") && ($row['start_time'] <= "09:00:00") )
return "absence_partial_m";
else if ( ($row['start_time'] >= "13:00:00") && ($row['start_time'] <= "18:00:00") )
return "absence_partial_a";
} else
// echo "full abs<br>";
return "absence_full";
}//
}
}
$numDays = monthDays($month, $year);
?>
<HTML>
<HEAD><TITLE>Vacation Plan</TITLE>
<script type="text/javascript">
function sort(form) {
var Page = "?";
var month = form.listMonth.selectedIndex+1;
var iyear = form.listYear.selectedIndex;
var year = form.listYear.options[iyear].value;
var URL = Page + "month=" + month + "&year=" + year;
window.location = URL;
return false;
}
</script>
<style type="text/css">
<!--
.style2 {font-size: 12px; }
td{ border:solid 1px red;}
-->
</style>
</HEAD>
<BODY>
<?
?>
<?php if (!empty($logoLink))
echo "<img src='$logoLink'/>";
?>
<center>
<div id="sort" style="padding-right: 10%">
<form id="frmSort" name="frmSort" onsubmit="return sort(this); return false;">
<?
$seeDate = date("F Y", strtotime($seeDate));
echo "<h2>".$seeDate."</h2>";
?>
<div align="right">
<strong>Month</strong>:
<?php
$curr_month = $month;
$auxmonth = array (1=>"January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December");
$select = "<select name=\"listMonth\">\n";
foreach ($auxmonth as $key => $val) {
$select .= "\t<option val=\"".$key."\"";
if ($key == $curr_month) {
$select .= " selected>".$val."\n";
} else {
$select .= ">".$val."\n";
}
}
echo $select;
?>
</select>
<img src="img/pixel.gif" width="1" height="1" /><img src="img/pixel.gif" width="1" height="1" /> <img src="img/pixel.gif" width="1" height="1" /><img src="img/pixel.gif" width="1" height="1" /> <img src="img/pixel.gif" width="1" height="1" /><strong>Year</strong>:
<select name="listYear" id="listYear">
<?php getYears($year); ?>
</select>
<img src="img/pixel.gif" width="1" height="1" /> <img src="img/pixel.gif" width="1" height="1" />
<input type="submit" name="Submit" value="Select" />
</form>
</div>
<div id="table">
<table width="90%" border="0" cellspacing="1" cellpadding="1">
<tr>
<td > </td>
<?
for($i = 1; $i <= $numDays; $i++) {
echo "<td bgcolor=\"#FFFFFF\" width=\"15\"><div align=\"center\"><strong>".$i."</strong></div></td>";
}
?>
</tr>
<?
global $db_host, $db_user, $db_pwd, $db_name, $db_port;
// $sql = "SELECT emp.*
// FROM hs_hr_employee AS emp
// INNER JOIN hs_hr_users AS users ON emp.emp_number = users.emp_number
// WHERE (users.status = 'Enabled')
// ORDER BY emp.emp_firstname ASC";
$sql = "SELECT emp.*
FROM hs_hr_employee AS emp
INNER JOIN ohrm_user AS users ON emp.emp_number = users.emp_number
WHERE (users.status = 1)
ORDER BY emp.emp_firstname ASC";
mysql_connect($db_host, $db_user, $db_pwd) or die(mysql_error());
mysql_select_db($db_name) or die(mysql_error());
$result = mysql_query($sql)or die(mysql_error());
$result_count = mysql_num_rows($result);
// echo "toto:$result_count<br>";
$even = 1;
while ($row = mysql_fetch_array( $result ) ) {
$employee_id = $row['employee_id'];
$employee_num = $row['emp_number'];
$employee_firstname = $row['emp_firstname'];
$employee_lastname = $row['emp_lastname'];
echo "<tr>";
if ( $even % 2)
echo " <td bgcolor=\"#FFFFFF\" width=\"10%\"><div align=\"right\">".$employee_firstname . " " . $employee_lastname . "</div></td>";
else
echo " <td bgcolor=\"#FFFFFF\" width=\"10%\"><div align=\"right\">".$employee_firstname . " " . $employee_lastname . "</div></td>";
$even++;
// echo "$even $numDays<br>";
for ($i = 1; $i <= $numDays; $i++) {
$day = checkDay($employee_num, $i, $month, $year);
// echo "$employee_num, $i, $month, $year $day<br>";
switch ($day) {
case 'holiday':
echo " <td bgcolor=\"#0000FF\"></td>";
break;
case 'weekend':
echo " <td bgcolor=\"#999999\"></td>";
break;
case 'absence_full':
echo " <td bgcolor=\"#FF0000\"></td>";
break;
case 'absence_partial_m':
echo " <td bgcolor=\"#FFFF00\"><center>M</center></td>";
break;
case 'absence_partial_a':
echo " <td bgcolor=\"#FFFF00\"><center>A</center></td>";
break;
default:
echo " <td bgcolor=\"##00FF00\"></td>";
break;
}//switch
}//for
echo "</tr>";
}//while
?>
</table>
</div>
</center>
<br/>
<div style="padding-left: 5%">
<table width="25%" border="0" cellspacing="1" cellpadding="1">
<tr>
<td bgcolor="#00FF00"> </td>
<td><div align="left" class="style2">Available</div></td>
</tr>
<tr>
<td width="11%" bgcolor="#FF0000"> </td>
<td width="89%"><div align="left" class="style2">Absence</div></td>
</tr>
<tr>
<td bgcolor="#CCCCCC"> </td>
<td><div align="left" class="style2">WeekEnd</div></td>
</tr>
<tr>
<td bgcolor="#0000FF"> </td>
<td><div align="left" class="style2">Public Holiday </div></td>
</tr>
<tr>
<td bgcolor="#FFFF00"><div align="center">M</div></td>
<td><div align="left" class="style2">Partial Absence (Morning) </div></td>
</tr>
<tr>
<td bgcolor="#FFFF00"><div align="center">A</div></td>
<td><span class="style2"> Partial Absence (Afternoon) </span></td>
</tr>
</table>
</div>
<br/>
<div align="center"> </div>
</BODY>
</HTML>
Thanks for sharing the code.
I seem to have got it working with 3.3! :)
I don't get the error you get.
Try adding debug code at the beginning: after
ini_set('display_errors', 'On');
I found that full day absence wasn't showing so I edited the code by removing
the comment at line 137:
} else
// echo "full abs";
return "absence_full";
not sure why I had to leave in semicolon though - thus:
} else
;
return "absence_full";
you need to turn short_tags on in PHP ini if you are going to use <? ?>
I have this text field
<?php if($row_questionset['Constructor']=="TextField"){?>
<?php while ($row_Answer=mysql_fetch_array($AnswersValue)){ ?>
<fieldset class="field" >
<?php $question=$row_questionset['QuestionIDFKPK'];?>
<span class="symbol">
<?php echo $row_questionset['QuestionValue']; ?>
<input class="validate[required] text-input" type="text" name="sampletextanswer<?= $row_Answer['QuestionIDFK'];?>[]" id=" < ?php echo $question ?> " value="<?= $answerSelect=$row_Answer['AnswerIDPK'] ; ?>" onblur="textfieldfocus()" <?php if ($row_Answer['UserAnswer']!='') {echo "checked=checked";} ?> >
</span>
</fieldset>
<?php } ?>
<?php } ?>
And i tried with these scripts for save in a table usage the info that user introduce on texfield each time that he click on it but don't works.What can i do ?
<script>
function textfieldfocus(){
var node_list = document.getElementsByTagName('input');
for (var i = 0; i < node_list.length; i++) {
var node = node_list[i];
if (node.getAttribute('type') == 'text'){
UpdateItem('<?php echo $US_ID ?>;' + this.id + ';' + this.value);
}
}
};
</script>