PHP - Apply Condition To The Output Based On The Count Value?
I'm not sure what am I doing wrong?
I want to check if match1, match2 or match 3 has "W" and the continues count ($numOfWinsCount) to be maximum of 2. If $numOfWinsCount is more than 2 do not continue with Code: [Select] $matchresult . $matchWcounter = "Qualified for Quarter Finals!"; My Code: Code: [Select] $match1 = "W" $match2 = "W" $match3 = "L" $getawayr="Group A"; if($getawayr=="Group A"){ for ( $matchWcounter = 1; $matchWcounter <= 3; $matchWcounter ++) { $numOfWinsCount = 0; if($match . $matchWcounter=="W" and $numOfWinsCount <3){ $numOfWinsCount=$numOfWinsCount+1; $matchresult . $matchWcounter = "Qualified for Quarter Finals!"; } } } Similar TutorialsI have the following code that queries the database for the results of a quiz. The display reports on completed quizzes, showing, line by line, the quiz title, the date of the quiz, an image of a green tick if the quiz result was correct or an image of a red cross for an incorrect result and a fractional result shoratio of correct answers. A student can repeat a quiz numerous times, and therefore his results for a particulat quiz can display several rows with green ticks and red crosses for the same test done at different times with differing results. I want to recode this so that the red crosses for incorrect results will no longer display once a student achieves a green tick result. I've had several goes at this but my results are less than encouraging. Can anyone help? Do I tackle this through an altered query, or should I include conditions in the display of the array? Code: [Select] <?php $query1 = mysql_query("SELECT DISTINCT quizTitle, userId, passState, userScore, totalScore, DATE_FORMAT(userDate,'%b %e, %Y') AS userDate FROM quiz WHERE managerId = '$managerId' AND userId = '$userId' ORDER BY quizTitle, userDate ASC"); while ($row = mysql_fetch_array($query1)) { echo "{$row['quizTitle']} <br />\n"; echo "{$row['userDate']} <br />\n"; if ("{$row['passState']}" == 1) {echo "<img src=' ../../wood/wood_tool_images/tick2.png' /><br />\n";} if ("{$row['passState']}" == 0) {echo "<img src=' ../../wood/wood_tool_images/cross2.png' /><br />\n";} echo "{$row['userScore']}".'/'."{$row['totalScore']} ?> Hi all, I'm wondering if it's possible to use the $numrows boolean parameter where $numrows = 0 and meets a condition. For instance, my code is set up to check for classes where $numrows>0 and then displays the classes. If $numrows < 1, it echoes a message saying there are no classes available and to call the training department. I would like to redirect one of the classes to another link by using a strpos function to search for the classname within the URL. As I understand it, I would have to embed it in the else part of the statement if it's at all possible. Here's what I have so far. if ($numrows > 0) { echo "<p align=\"left\" class=\"style2 style4\">Click in the check box next to the date for which you would like to register: </p>"; echo "<p align=\"left\" class=\"style2 style4\">" . $_GET['classname'] . "</p>"; echo "<table width=100% style=\"color:#FFFFFF\">"; echo "<th></th>"; echo "<th>Date</th>"; echo "<th>Time</th>"; echo "<th>Location</th>"; echo "<th>Instructor</th>"; while ($results = mysql_fetch_array($rs)){ echo "<tr>"; echo "<td><input type=\"radio\" name=\"checkbox\" value=\"" . $results['date'] . "|" . $results['time'] . "|" . $results['location'] . "|" . $results['instructor'] . "|" . $results['course'] . "\"" . "></td>"; echo "<td class=\"style11\">" . $results['date'] . "</td>"; echo "<td class=\"style11\">" . $results['time'] . "</td>"; echo "<td class=\"style11\">" . $results['location'] . "</td>"; echo "<td class=\"style11\">" . $results['instructor'] . "</td>"; echo "</tr>"; } echo "</table>"; } elseif (strpos($_REQUEST['classname'], "BloodBorne Pathogens Video")); { echo "Bloodborne Pathogens is exclusively offered online. Please <a href=../training/online_courses/Bloodborne/BB.html>click here</a> to take the course."; } else { echo "Please call the training department as there are no classes scheduled at this time." } Please let me know if this is even possible or if I'm off my rocker. I'm fairly new to the PHP world but not a newb Thanks a bunch for your time! Hi all.
In my database, i have a table where a client chose a service providers to make payments and each bill setup counts as a reward point for the client. Each bill counts as a single point even if the bill is edited after a services might have expired or renewed it should not be counted again as point.
to count the number of bill set up by a client i did
$stmt = $pdo->prepare("UPDATE reward_points SET num_bill = num_bill + 1 WHERE username = '$username' AND acct_num = '$acct_num'"); $stmt->execute();Its okay if it counts for new bills but i want it not to count for the same service provide and so i did $stmt=$pdo->query("SELECT company FROM payment WHERE username = '$username' AND trans_ref = '$trans_ref'"); while($row = $stmt->fetch(PDO::FETCH_ASSOC)) { $coy = $row['company']; } //ps: note, $company is a variable from the form if(strcmp($coy, $company) == 0){ $stmt = $pdo->prepare("UPDATE reward_points SET num_bill = num_bill + 0 WHERE username = '$username' AND acct_num = '$acct_num'"); $stmt->execute(); }elseif(strcmp($coy, $company) != 0){ $stmt = $pdo->prepare("UPDATE reward_points SET num_bill = num_bill + 1 WHERE username = '$username' AND acct_num = '$acct_num'"); $stmt->execute(); }it just wont add up i also tried $coy1 = $coy; $coy2 = $company; $point = 0; if(strcmp($coy1, $coy2) == 0){ $add_point = $point + 0; }else{ $add_point = $point + 1; } $stmt = $pdo->prepare("UPDATE reward_points SET num_bill = $add_point WHERE username = '$username' AND acct_num = '$acct_num'"); $stmt->execute();still wont work. any idea? Hi My website is a Wordpress WooCommerce. I modified the PHP function that worked well before I added the multiple customer roles. I have regular customers and regular and tier-level wholesalers. I live in Canada and with have two taxes to apply (GST & PST). We also have customers/wholesalers that get exempted from one tax (PST) only or both taxes. I have one regular wholesale role with two tax exemption roles: 'wholesale_customer', 'wholesale_pst_exempt', 'wholesale_tax_exempt'. I have 4 tier levels wholesale roles with each their own tax exemption roles: 'wholesale_silvia_silver', 'wholesale_silvia_gold', 'wholesale_silvia_premium', 'wholesale_silvia_union' 'wholesale_silvia_silver_pst_exempt', 'wholesale_silvia_gold_pst_exempt', 'wholesale_silvia_premium_pst_exempt', 'wholesale_silvia_union_pst_exempt' 'wholesale_silvia_silver_tax_exempt', 'wholesale_silvia_gold_tax_exempt', 'wholesale_silvia_premium_tax_exempt', 'wholesale_silvia_union_tax_exempt' The tier levels are new and I'm trying to update my existing function that applies different tax rates based on customer user roles. I also have filters to alter the shipping tax for the different tax class based on the customer role. Here are the function and filter that I have updated to add the additional tier level wholesale roles. The changes I've made are not working because I don't see the tax exemptions. Both taxes are always being applied. Can someone help me figure out what I've done wrong to the code that stopped it from working? I'm not proficient in PHP, so was trying my best to make this work. /* * APPLY DIFFERENT TAX RATE BASED ON CUSTOMER USER ROLE * (Code compacted in one unique hook instead of 5 functions with the same hook) */ function all_custom_tax_classes( $tax_class, $product ) { global $current_user; // Getting the current user $curr_user = wp_get_current_user(); $curr_user_data = get_userdata($current_user->ID); // 1 customer_tax_exempt /* special tax rate: zero if role: Customer Tax Exempt */ /*if ( in_array( 'customer_tax_exempt', $curr_user_data->roles ) ) $tax_class = 'CustomerTaxExemptClass'; // 2 customer_pst_exempt // special tax rate: charge only GST if role: Customer PST Exempt if ( in_array( 'customer_pst_exempt', $curr_user_data->roles ) ) $tax_class = 'CustomerPSTExemptClass'; */ // 3, 4 & 5 WHOLESLE SUITE SPECIAL WHOLESALE TAX RATES if (isset($current_user) && class_exists('WWP_Wholesale_Roles')) { $wwp_wholesale_roles = WWP_Wholesale_Roles::getInstance(); $wwp_wholesale_role = $wwp_wholesale_roles->getUserWholesaleRole(); // special tax rate: charge both PST and GST if roles: Wholesale Customer, Wholesale Silvia Silver, Wholesale Silvia Gold, Wholesale Silvia Premium, Wholesale Silvia Union if (!empty($wwp_wholesale_role) && in_array('wholesale_customer', $wwp_wholesale_role) && in_array('wholesale_silvia_silver', $wwp_wholesale_role) && in_array('wholesale_silvia_gold', $wwp_wholesale_role) && in_array('wholesale_silvia_premimum', $wwp_wholesale_role) && in_array('wholesale_silvia_union', $wwp_wholesale_role)) { // Where 'wholesale_customer, wholesale_silvia_silver, wholesale_silvia_gold, wholesale_silvia_premium, wholesale_silvia_union' are the names of the wholesale roles to target $tax_class = 'WholesalePSTGST'; } // special tax rate: charge only GST if roles: Wholesale PST Exempt, Wholesale Silvia Silver PST Exempt, Wholesale Silvia Gold PST Exempt, Wholesale Silvia Premium PST Exempt, Wholesale Silvia Union PST Exempt if (!empty($wwp_wholesale_role) && in_array('wholesale_pst_exempt', $wwp_wholesale_role) && in_array('wholesale_silvia_silver_pst_exempt', $wwp_wholesale_role) && in_array('wholesale_silvia_gold_pst_exempt', $wwp_wholesale_role) && in_array('wholesale_silvia_premium_pst_exempt', $wwp_wholesale_role) && in_array('wholesale_silvia_union_pst_exempt', $wwp_wholesale_role)) { // Where 'wholesale_pst_exempt, wholesale_silvia_silver_pst_exempt, wholesale_silvia_gold_pst_exempt, wholesale_silvia_premium_pst_exempt, wholesale_silvia_union_pst_exempt' are the names of the wholesale roles to target $tax_class = 'WholesalePSTExempt'; } // special tax rate: zero if roles: Wholesale Tax Exempt, Wholesale Silvia Silver Tax Exempt, Wholesale Silvia Gold Tax Exempt, Wholesale Silvia Premium Tax Exempt, Wholesale Silvia Union Tax Exempt if (!empty($wwp_wholesale_role) && in_array('wholesale_tax_exempt', $wwp_wholesale_role) && in_array('wholesale_silvia_silver_tax_exempt', $wwp_wholesale_role)&& in_array('wholesale_silvia_gold_tax_exempt', $wwp_wholesale_role) && in_array('wholesale_silvia_premium_tax_exempt', $wwp_wholesale_role) && in_array('wholesale_silvia_union_tax_exempt', $wwp_wholesale_role)) { // Where 'wholesale_tax_exempt, wholesale_silvia_silver_tax_exempt, wholesale_silvia_gold_tax_exempt, wholesale_silvia_premium_tax_exempt, wholesale_silvia_union_tax_exempt' are the names of the wholesale role to target $tax_class = 'WholesaleZeroTax'; } } return $tax_class; } /* ADDITIONAL FILTERS TO ALTER THE SHIPPING TAX FOR DIFFERENT TAX CLASSES BASED ON CUSTOMER USER ROLE */ add_filter( 'woocommerce_product_get_tax_class', 'all_custom_tax_classes', 1, 2 ); add_filter( 'woocommerce_product_variation_get_tax_class', 'all_custom_tax_classes', 1, 2 ); add_filter( 'option_woocommerce_shipping_tax_class' , function( $option_value ) { global $wc_wholesale_prices; if ( $wc_wholesale_prices && is_a( $wc_wholesale_prices , 'WooCommerceWholeSalePrices' ) ) { $current_user_wholesale_roles = $wc_wholesale_prices->wwp_wholesale_roles->getUserWholesaleRole(); if ( in_array( 'wholesale_customer', $current_user_wholesale_roles ) ){ return 'wholesalepstgst'; } elseif (in_array( 'wholesale_silvia_silver', $current_user_wholesale_roles) ){ return 'wholesalepstgst'; } elseif (in_array( 'wholesale_silvia_gold', $current_user_wholesale_roles) ){ return 'wholesalepstgst'; } elseif (in_array( 'wholesale_silvia_premium', $current_user_wholesale_roles) ){ return 'wholesalepstgst'; } elseif (in_array( 'wholesale_silvia_union', $current_user_wholesale_roles) ){ return 'wholesalepstgst'; } elseif (in_array( 'wholesale_pst_exempt', $current_user_wholesale_roles) ){ return 'wholesalepstexempt'; } elseif (in_array( 'wholesale_silvia_silver_pst_exempt', $current_user_wholesale_roles) ){ return 'wholesalepstexempt'; } elseif (in_array( 'wholesale_silvia_gold_pst_exempt', $current_user_wholesale_roles) ){ return 'wholesalepstexempt'; } elseif (in_array( 'wholesale_silvia_premium_pst_exempt', $current_user_wholesale_roles) ){ return 'wholesalepstexempt'; } elseif (in_array( 'wholesale_silvia_union_pst_exempt', $current_user_wholesale_roles) ){ return 'wholesalepstexempt'; } elseif (in_array( 'wholesale_tax_exempt', $current_user_wholesale_roles) ){ return 'wholesalezerotax'; } elseif (in_array( 'wholesale_silvia_silver_tax_exempt', $current_user_wholesale_roles) ){ return 'wholesalezerotax'; } elseif (in_array( 'wholesale_silvia_gold_tax_exempt', $current_user_wholesale_roles) ){ return 'wholesalezerotax'; } elseif (in_array( 'wholesale_silvia_premium_tax_exempt', $current_user_wholesale_roles) ){ return 'wholesalezerotax'; } elseif (in_array( 'wholesale_silvia_union_tax_exempt', $current_user_wholesale_roles) ){ return 'wholesalezerotax'; } } return $option_value; } , 10 , 1 );
Thank you Lyse Edited June 18, 2019 by LyseSpecify website platforms I have two css external style sheets. One for the 800x600 screen resolution and other for 1200x768. How can I detect the screen resolution and apply the according style sheet using PHP. If I use Javascript, It is possible that the Javascript may not be enable on client side. has some one a better solution? I have a "Users" table. I would like to find out the average users sign up in total. This table has a "joined date" column so I can track how many users sign up in a single day. For e.g. August 16 - 10 users August 17 - 20 users Auguest 18 - 30 users The total average of user sign ups would be 20 users based on the above results. So I am wondering how can I create this function? This is my starting query. $get_users = $db->prepare("SELECT user_id FROM users"); $get_users->execute(); $result_users = $get_users->fetchAll(PDO::FETCH_ASSOC); if(count($result_users) > 0) { foreach($result_users as $row) { $user_id = $row['user_id']; } }
I am using magento for sending mail with condition, My code: <?php class Gta_MerchantNotification_Model_Observer { public function merchantremainder($Observer) { $order = $Observer->getEvent()->getOrder(); $order_details = $order->getAllVisibleItems(); $itemData = array(); foreach ($order_details as $list) { $incrementid = $order->getIncrementId(); $sku = $list->getsku(); $name = $list->getName(); $price = $list->getPrice(); $Qty = $list->getQtyOrdered(); $extra = $order->getIncrementId(); $message = " <tr> <!-- <td>$incrementid</td> --> <td>$sku</td> <td>$name</td> <td>$price</td> <td>$Qty</td> </tr>"; $itemData[$list->getId()] = $message; } $finalMessage = " <p>Order Id : $incrementid</p> <table border='1'> <tr> <!-- <th>Id</th> --> <th>Sku</th> <th>Product name</th> <th>Price</th> <th>Qty Ordered</th> </tr>"; if (!empty($itemData)) { foreach ($itemData as $data) { $finalMessage .= $data; } $finalMessage .= "</table>"; $this->sendMail($finalMessage); } } public function sendMail($message) { $body ="$message"; $emailTemplate = Mage::getModel('core/email'); $emailTemplate->setFromName('abc'); $emailTemplate->setBody($body); $emailTemplate->setSubject("Custom Email from observer"); $emailTemplate->setType('html'); $emailTemplate->setToEmail('abc@gmail.com'); $emailTemplate->send(); } } ?>
Output :
If order placed mail send to abc@gmail.com. I want :
1) If SKU starts with 2, email should go to the mail id abc@gmail.com,
2) If SKU starts with 3, email should go to the mail id xyz@gmail.com,
3) If SKU starts with 4, email should go to the mail id qwe@gmail.com,
FYI - If an order contains 10 items email should go separately based on SKU. But an order id the same must include all the emails.
hey guys, I am having a small problem and I can't wrap my head around it. I want users to be able to upload up 10 photos in the database and what I want to do is check the database to see how many pics they have already and if they have 10, just show the photo with action items but if they have 7 for example, show the 7 pictures and three upload fields, if they have 4, show the pics and 6 fields and so on... let me know what you guys think and some help. Thanks in advance guys, you always come through... Hi guys, I need your help. I am trying to insert the rows in the mysql database as I input the values in the url bar which it would be like this: Code: [Select] www.mysite.com/testupdate.php?user=tester&pass=test&user1=tester&email=me@shitmail.com&ip=myisp However i have got a error which i don't know how to fix it. Error: Column count doesn't match value count at row 1 <?php session_start(); define('DB_HOST', 'localhost'); define('DB_USER', 'mydbusername'); define('DB_PASSWORD', 'mydbpassword'); define('DB_DATABASE', 'mydbname'); $errmsg_arr = array(); $errflag = false; $link = mysql_connect(DB_HOST, DB_USER, DB_PASSWORD); if(!$link) { die('Failed to connect to server: ' . mysql_error()); } $db = mysql_select_db(DB_DATABASE); if(!$db) { die("Unable to select database"); } function clean($var){ return mysql_real_escape_string(strip_tags($var)); } $username = clean($_GET['user']); $password = clean($_GET['pass']); $adduser = clean($_GET['user1']); $email = clean($_GET['email']); $IP = clean($_GET['ip']); if($username == '') { $errmsg_arr[] = 'username is missing'; $errflag = true; } if($password == '') { $errmsg_arr[] = 'PASSWORD is missing'; $errflag = true; } if($errflag) { $_SESSION['ERRMSG_ARR'] = $errmsg_arr; echo implode('<br />',$errmsg_arr); } else { $sql = "INSERT INTO `members` (`username`,`email`,`IP`) VALUES ('$adduser','$email','$IP')"; if (!mysql_query($sql,$link)) { die('Error: ' . mysql_error()); } echo "The information have been updated."; } ?> Here's the name of the columns i have got in my database: Code: [Select] username IP I have input the correct columns names, so I can't correct the problem I am getting. Please can you help? This topic has been moved to MySQL Help. http://www.phpfreaks.com/forums/index.php?topic=331562.0 Why am I getting this error when there are 3 Fields with 3 values? Column count doesn't match value count at row 1 Code: [Select] $sql5="INSERT INTO participants (participant_name, team_no, sport) VALUES ('".implode("','$_POST[team]'),('",$_POST['participant_name'])."','$_POST[team]','$sport')"; Anyone can help me? <?php $tbl_name="menu"; $kategorije = mysql_query("SELECT * FROM $tbl_name WHERE Left(menu_name, 1) BETWEEN 'A' AND 'M' ORDER BY menu_name ASC"); if (!$kategorije) { die("Database query failed: " . mysql_error()); } while ($row=mysql_fetch_array( $kategorije )) { echo "<div id=lista-header><h4>{$row["menu_name"]}</h4></div>"; $id_sub=$row['id_menu']; $podkategorije = mysql_query("SELECT * FROM submenu WHERE id_menu=$id_sub ORDER BY sub_name ASC", $connection); if (!$podkategorije) { die("Database query failed: " . mysql_error()); } echo "<ul class=\"pod\">"; while ($pod=mysql_fetch_array( $podkategorije )) { echo "<li><a href=index.php?=podkate?".$pod["id_sub"]." class=black>{$pod["sub_name"]}</a><hr size=1 align=left width=100px color=#cccccc></li>"; } echo "</ul>"; } ?> In this way, I get list with categories and hes subcategories. How to count how many subcategories have each categories, and count how many articles have each categories? Example (I wanna get this kind of look): Categories name (3) subcategoriesname (2) subcategoriesname (4) subcategoriesname (7) Categories name (5) subcategoriesname (1) subcategoriesname (14) subcategoriesname (9) subcategoriesname (2) subcategoriesname ( Categories name (2) subcategoriesname (28) subcategoriesname (17) Where the numbers represent how many categories and sub-items have articles Well I have a script that executes a scan on a system set to run infinitely, and I need it to echo out a message each time it loops through, but I don't want it to echo out the message with the next loop message below it, and the next one below that etc... I've tried using the flush(); function and been messing around with that with no luck. For security reasons I don't want to release any of the processing code, but here is the basic construction of the script: <?PHP ***PROCESSING AND SCAN CODE*** ***PROCESSING AND SCAN CODE*** ***PROCESSING AND SCAN CODE*** ***PROCESSING AND SCAN CODE*** $RepeatIt = -1; for($g=1; $g!=$RepeatIt+1; $g++) { ***PROCESSING AND SCAN CODE*** ***PROCESSING AND SCAN CODE*** ***PROCESSING AND SCAN CODE*** ***PROCESSING AND SCAN CODE*** $ScanMessage = ":.:.: SCANNING THE HITLIST FOR MOBSTER: ".$MobName." (SCAN #$g) :.:.:"."<br/><br/>"; echo $ScanMessage; ***PROCESSING AND SCAN CODE*** ***PROCESSING AND SCAN CODE*** ***PROCESSING AND SCAN CODE*** ***PROCESSING AND SCAN CODE*** } ?> At the moment it's returning: :.:.: SCANNING THE HITLIST FOR MOBSTER: DEUS EX DESTROYER (SCAN #1) :.:.: :.:.: SCANNING THE HITLIST FOR MOBSTER: DEUS EX DESTROYER (SCAN #2) :.:.: :.:.: SCANNING THE HITLIST FOR MOBSTER: DEUS EX DESTROYER (SCAN #3) :.:.: :.:.: SCANNING THE HITLIST FOR MOBSTER: DEUS EX DESTROYER (SCAN #4) :.:.: So what I want it to do is just delete the scanning message and replace it with the next scan message so while running this script you would see just the number increment on the same line. Any suggestions? Thanks. I have this if statement with validations and mysql query Code: [Select] <?php if(isset($_POST['submit'])) { $errors = array(); $required_fields = array('menu_name', 'position', 'visible'); foreach($required_fields as $fieldname) { if(!isset($_POST[$fieldname]) || (empty($_POST[$fieldname]) && $_POST[$fieldname] != 0)) { $errors[] = $fieldname; } } $fields_with_length = array('menu_name' => 30); foreach($fields_with_length as $fieldname => $maxlength) { if (strlen(trim(mysql_prep($_POST[$fieldname]))) > $maxlength) { $errors[] = $fieldname; } } if(empty($errors)) { //Perform Update $id = mysql_prep($_GET['subj']); $menu_name = mysql_prep($_POST['menu_name']); $position = mysql_prep($_POST['position']); $visible = mysql_prep($_POST['visible']); $query = "UPDATE subjects SET menu_name = '{$menu_name}', position = {$position}, visible = {$visible} WHERE id = {$id}"; $result = mysql_query($query, $connection); if(mysql_affected_rows() == 1) { //success $message = "Record has been successfuly updated!"; } else { //failed $message = "The subject update failed"; $message .= "<br>". mysql_error(); } } else { //Error Occured $message = "There were ". count($errors) . " error in the form"; } } ?> I'm having problem on this line Code: [Select] <?php if(!isset($_POST[$fieldname]) || (empty($_POST[$fieldname]) && $_POST[$fieldname] != 0)) ?> this line is for validation of my radio button which has a 0 and 1 value. Quote && $_POST[$fieldname] != 0 Eventhough the textbox is not set and is empty, it's still bypassing my if statement and still executing the update query... this code works fine if the conditions are absolute ( pass, fail or empty). im trying to make the fail work if its part of the query. ive tried %fail% but didnt work. $choice = strtoupper($rows['comments']); if($choice == "PASS"){ $bgc = "#ff25f0" ; } elseif($choice == "FAIL"){ $bgc = "#666666" ; }else{ $bgc = "#FF6600" ; } if u use this for one condition if ($nr > 5) how would u check if the nr is between 5 and 50 thanks ! Code: [Select] if($this->color=="Blue" || $this->color=="Green" || $this->color=="Red" || $this->color=="Yellow") { return true; } else { return false; } This is returning false, when it should be returning true because $this->color DOES equal "Red"... I can NEVER EVER get these conditional things to work UNLESS it's &&, but I even tried: !$this->color != "Red" && ......... as well to see if that would work even though that's really confusing. Can someone help me finally understand this stupid OR stuff? Hi.. I have form for leave and now I need to add checkbox for halfday. if checkbox is checked the HOURS_LEAVE = HOURS_LEAVE * 4 because his leave is halfday only. then if checkbox is not check the HOURS_LEAVE = HOURS_LEAVE * 8 . and also if checkbox is check the value is H else W then it also save to database here is my code for LeaveEmp.php <?php include 'config.php'; date_default_timezone_set('Asia/Singapore'); session_start(); $currentEmpID = $_SESSION['empID']; $EMP_NO = $_GET['EMP_NO']; $NAME = $_GET['NAME']; $DATE_LEAVE_FROM = $_GET['DATE_LEAVE_FROM']; $DATE_LEAVE_TO = $_GET['DATE_LEAVE_TO']; $HOURS_LEAVE = $_GET['HOURS_LEAVE']; $Approve = $_GET['Approve']; $TYPE =$_GET['TYPE']; $dateprocess = $_GET['dateprocess']; $DATE_LEAVE = $_GET['DATE_LEAVE']; $EMPNO = $_GET['EMPNO']; function GetDays($StartDate, $EndDate){ $StartDate = date("Y-m-d", strtotime($StartDate)); $EndDate = date("Y-m-d", strtotime($EndDate)); $Days[] = $StartDate; $CurrentDate = $StartDate; while($CurrentDate < $EndDate){ $CurrentDate = date("Y-m-d", strtotime("+1 day", strtotime($CurrentDate))); if(date("w",strtotime($CurrentDate))>0){ $Days[] = $CurrentDate; } } return count($Days); } $HOURS_LEAVE = GetDays($DATE_LEAVE_FROM, $DATE_LEAVE_TO); $smarty->assign('LeaveStatus', array(SickLeave=>'Sick Leave',VacationLeave=>'Vacation Leave',BirthdayLeave=>'Birthday Leave',MaternityLeave=>'Maternity Leave', PaternityLeave=>'Paternity Leave', UnionLeave=>'Union Leave', Holiday=>'Holiday')); $smarty->assign('TYPE', $TYPE); $sql = "SELECT l.EMP_NO, l.DATE_LEAVE_FROM, l.DATE_LEAVE_TO, l.HOURS_LEAVE, l.TYPE_LEAVE, l.STATUS_LEAVE FROM $ADODB_DB.employment em, $PAYROLL.leave_data l WHERE em.EMP_NO = l.EMP_NO AND em.EMP_ID = '$currentEmpID' AND l.DATE_LEAVE_FROM = '$DATE_LEAVE_FROM'"; $result_edit = $conn2->Execute($sql); $DATE_LEAVE_FROM = $result_edit->fields['DATE_LEAVE_FROM']; $DATE_LEAVE_TO = $result_edit->fields['DATE_LEAVE_TO']; $smarty->assign('DATE_LEAVE_FROM', $DATE_LEAVE_FROM); $smarty->assign('DATE_LEAVE_TO', $DATE_LEAVE_TO); $sql = "SELECT l.EMP_NO, p.EMP_ID, CONCAT(LNAME, ', ', FNAME, ' ', MI, '.') AS FULLNAME, l.DATE_LEAVE_FROM, l.DATE_LEAVE_TO, l.HOURS_LEAVE, l.TYPE_LEAVE, l.STATUS_LEAVE FROM $ADODB_DB.PERSONAL p, $ADODB_DB.employment em, $PAYROLL.leave_data l WHERE em.EMP_NO = l.EMP_NO AND p.EMP_ID = em.EMP_ID ORDER BY FULLNAME"; $rs = $conn2->GetAll($sql); $smarty->assign('getleave', $rs); $smarty->display('header_att.tpl'); $smarty->display('LeaveForm.tpl'); $smarty->display('footer.tpl'); ?> here is my code for saving leave: <?php include 'config.php'; date_default_timezone_set('Asia/Singapore'); $currentEmpID = $_SESSION["empID"]; $EMP_NO = $_GET['EMP_NO']; $NAME = $_GET['NAME']; $DATE_LEAVE_FROM = $_GET['DATE_LEAVE_FROM']; $DATE_LEAVE_TO = $_GET['DATE_LEAVE_TO']; $HOURS_LEAVE = $_GET['HOURS_LEAVE']; $TYPE =$_GET['TYPE']; $Approve = $_GET['Approve']; $dateprocess = $_GET['dateprocess']; $today = date("Y-m-d"); function GetDays($StartDate, $EndDate){ $StartDate = date("Y-m-d", strtotime($StartDate)); $EndDate = date("Y-m-d", strtotime($EndDate)); $Days[] = $StartDate; $CurrentDate = $StartDate; while($CurrentDate < $EndDate){ $CurrentDate = date("Y-m-d", strtotime("+1 day", strtotime($CurrentDate))); if(date("w",strtotime($CurrentDate))>0){ $Days[] = $CurrentDate; } } return count($Days); } $HOURS_LEAVE = GetDays($DATE_LEAVE_FROM, $DATE_LEAVE_TO); $HOURS_LEAVE = $HOURS_LEAVE * 8; $smarty->assign('LeaveStatus', array(SickLeave=>'Sick Leave',VacationLeave=>'Vacation Leave',BirthdayLeave=>'Birthday Leave',MaternityLeave=>'Maternity Leave', PaternityLeave=>'Paternity Leave', UnionLeave=>'Union Leave', Holiday=>'Holiday')); $smarty->assign('TYPE', $TYPE); $smarty->assign('DATE_LEAVE_FROM', $DATE_LEAVE_FROM); $smarty->assign('DATE_LEAVE_TO', $DATE_LEAVE_TO); $smarty->assign('EMP_NO', $EMP_NO); $smarty->assign('NAME', $NAME); $smarty->assign('HOURS_LEAVE', $HOURS_LEAVE); $smarty->assign('TYPE', $TYPE); $smarty->assign('dateprocess', $today); $sql = "SELECT EMP_NO, DATE_LEAVE_FROM, DATE_LEAVE_TO, HOURS_LEAVE, TYPE_LEAVE, STATUS_LEAVE, DATE_PROCESS FROM leave_data WHERE EMP_NO = '$EMP_NO' AND DATE_LEAVE_FROM = '$DATE_LEAVE_FROM' AND DATE_LEAVE_TO = '$DATE_LEAVE_TO'"; $RsLeave = $conn2->Execute($sql); $numrowsRsLeave = $RsLeave->RecordCount(); if($numrowsRsLeave > 0){ echo "<script>alert('Transaction has already been process')</script>"; echo "<script>navigate('LeaveEmp.php')</script>"; } else { $sql = "SELECT EMP_NO, DATE_LEAVE_FROM, DATE_LEAVE_TO, HOURS_LEAVE, TYPE_LEAVE, STATUS_LEAVE, DATE_PROCESS FROM leave_data WHERE EMP_NO = '$EMP_NO' AND DATE_LEAVE_FROM = '$DATE_LEAVE_FROM' AND DATE_LEAVE_TO = '$DATE_LEAVE_TO'"; $RsLeave = $conn2->Execute($sql); $saverec['EMP_NO'] = $EMP_NO; $saverec['DATE_LEAVE_FROM'] = $DATE_LEAVE_FROM; $saverec['DATE_LEAVE_TO'] = $DATE_LEAVE_TO; $saverec['HOURS_LEAVE'] = $HOURS_LEAVE; $saverec['TYPE_LEAVE'] = $TYPE; $saverec['STATUS_LEAVE'] = $Approve; $saverec['DATE_PROCESS'] = $today; $insertSQL = $conn2->GetInsertSQL($RsLeave, $saverec); $conn2->Execute($insertSQL); } $sql = "SELECT EMP_NO, DATE_LEAVE_FROM, DATE_LEAVE_TO, HOURS_LEAVE, TYPE_LEAVE, STATUS_LEAVE, DATE_PROCESS FROM leave_log WHERE EMP_NO = '$EMP_NO' AND DATE_LEAVE_FROM = '$DATE_LEAVE_FROM' AND DATE_LEAVE_TO = '$DATE_LEAVE_TO'"; $RsLeaveLog = $conn2->Execute($sql); $numrowsRsLeave = $RsLeaveLog->RecordCount(); if($numrowsRsLeave > 0){ echo "<script>alert('Transaction has already been process')</script>"; echo "<script>navigate('LeaveEmp.php')</script>"; } else{ $sql = "SELECT EMP_NO, DATE_LEAVE_FROM, DATE_LEAVE_TO, HOURS_LEAVE, TYPE_LEAVE, STATUS_LEAVE, DATE_PROCESS FROM leave_log WHERE EMP_NO = '$EMP_NO' AND DATE_LEAVE_FROM = '$DATE_LEAVE_FROM' AND DATE_LEAVE_TO = '$DATE_LEAVE_TO'"; $RsLeaveLog = $conn2->Execute($sql); $saverec['EMP_NO'] = $EMP_NO; $saverec['DATE_LEAVE_FROM'] = $DATE_LEAVE_FROM; $saverec['DATE_LEAVE_TO'] = $DATE_LEAVE_TO; $saverec['HOURS_LEAVE'] = $HOURS_LEAVE; $saverec['TYPE_LEAVE'] = $TYPE; $saverec['STATUS_LEAVE'] = $Approve; $saverec['DATE_PROCESS'] = $today; $insertSQL = $conn2->GetInsertSQL($RsLeaveLog, $saverec); $conn2->Execute($insertSQL); } session_write_close(); header("Location:LeaveEmp.php"); exit(); ?> And here is the LeaveForm.tpl <script> window.onload = function() { var ul = document.getElementById('searchpayroll'); var links = ul.getElementsByTagName('a'); var i = 0; document.onkeyup = function(e){ e = window.event || e; var key = e.charCode || e.keyCode; if (key == 40) { if (i < links.length - 1) i++; links[i].focus(); } else if (key == 38) { if (i > 0) i--; links[i].focus(); } } } function ApproveLeaveOP(){ var EMP_NO = document.getElementById('EMP_NO').value; var DATE_LEAVE_FROM = document.getElementById('DATE_LEAVE_FROM').value; var DATE_LEAVE_TO = document.getElementById('DATE_LEAVE_TO').value; var NAME = document.getElementById('NAME').value; var HOURS_LEAVE = document.getElementById('HOURS_LEAVE').value; var Approve = document.getElementById('Approve').value; var TYPE = document.getElementById('TYPE').value; var dateprocess = document.getElementById('dateprocess').value; var H = document.getElementById('H').value; document.sampleform.action="AddLeave.php?EMP_NO="+EMP_NO+"&DATE_LEAVE_FROM="+DATE_LEAVE_FROM+"&DATE_LEAVE_TO="+DATE_LEAVE_TO+"&NAME="+NAME+"&HOURS_LEAVE="+HOURS_LEAVE+"&Approve="+Approve+"&TYPE="+TYPE+"&dateprocess="+dateprocess+"&H="+H; document.sampleform.submit(); } </script> <script type="text/javascript" src="op_from_date_leave.js"> </script> <script type="text/javascript" src="op_from_date_leave_conf2.js"></script> <div id="Search"> <form> <p class="serif"><b>Search Lastname:</b></p> <input type="text" name="search_" size="20" onkeyup="searchEmpLeaveOP(this.value);"> <div> <hr /> <ul id="searchpayroll" style="overflow:auto; height:380px; width:100%; margin-left:2px;"> {section name=co_emp loop=$personalAll} <li><a href="LeaveData.php?queryEmpID={$personalAll[co_emp].EMP_ID}">{$personalAll[co_emp].FULLNAME}</a></li> <hr /> {sectionelse} <li>No records found</li> {/section} </ul> </div> <div id="EmpOTForm"> <fieldset> <legend>Overtime and Leave Form</legend> <input type="button" name="OTbtn" value="Overtime" onclick="OtFrmOP()")> <input type="button" name="Leavebtn" value="Leave" onClick="LeaveOP()"> <p class="serif"> <label id="LeaveEmpIDLabel">EMP ID</label><label id="LeaveNameLabel">NAME</label><label id="FromLeave"><a href="Javascript:showCal('RegCalendar1')">FROM DATE </a></label><label id="DaysLabel"><a href="Javascript:showCal('RegCalendar2')">TO DATE</a></label><label id="TypeLeave">LEAVE TYPE</label><label id="HLeave">H</label> <input type="text" name="EMP_NO" id="EMP_NO" value="{$empno}" size="8" > <input type="text" name="NAME" id="NAME" value="{$fullname}" size="35" > <input type="text" name="DATE_LEAVE_FROM" id="DATE_LEAVE_FROM" value="{$DATE_LEAVE_FROM}" size="9"> <input type="text" name="DATE_LEAVE_TO" id="DATE_LEAVE_TO" value="{$DATE_LEAVE_TO}" size="9"> {html_options id=TYPE name=TYPE options=$LeaveStatus selected=$TYPE style="width:140px;"} <input type="checkbox" name="H" id="H" value=""> <input type="button" name="Approve" value="Approve" id="Approve" onclick="ApproveLeaveOP()"> <input type="button" name="Edit" value="Edit" id="Edit" onclick="EditLeaveOP()"> <input type="hidden" name="dateprocess" id="dateprocess" value="{$dateprocess}"> </p> <input type="hidden" id="HOURS_LEAVE"> </fieldset> <div> <p> <table border="1" class="stat" width="auto"> <tr> <th>EMP ID</th> <th>NAME</th> <th>FROM DATE</th> <th>TO DATE</th> <th># of HOURS</th> <th>TYPE</th> <th>STATUS</th> </tr> {section name=att loop=$getleave} <tr> <td id = "EMPNO">{$getleave[att].EMP_NO}</td> <td >{$getleave[att].FULLNAME}</td> <td id = "DATE_LEAVE" onclick="opleave_edit('{$getleave[att].DATE_LEAVE_FROM}')">{$getleave[att].DATE_LEAVE_FROM}</td> <td >{$getleave[att].DATE_LEAVE_TO}</td> <td >{$getleave[att].HOURS_LEAVE}</td> <td >{$getleave[att].TYPE_LEAVE}</td> <td >{$getleave[att].STATUS_LEAVE}</td> </tr> {/section} </table> </p> </form> </div> </div> </div> I attach the sample form. Thank you |