Jump to content

michelle1404

Members
  • Posts

    41
  • Joined

  • Last visited

Everything posted by michelle1404

  1. Yes, This is the query SELECT eemp_id, AVG(DATEDIFF( IF(leaving_date is null or leaving_date = '' or leaving_date='0000-00-00', CURRENT_DATE(), leaving_date), joining_date )) AS Days FROM employee_deatils group by eemp_id
  2. I am trying to select all the employees who have Minimum average years of experience of 3 years. If an employee worked for 24 years in 3 companies the average years of experience is 8 years. For this i got result by doing like this SELECT AVG(DATEDIFF( IF(leaving_date is null or leaving_date = '' or leaving_date='0000-00-00', CURRENT_DATE(), leaving_date), joining_date )) AS Days FROM employee_deatils WHERE eemp_id=? Now while searching of those employees who have worked minimum 3 years (avg) in a company, i am not able to get the results. When i run this query in phpmyadmin, SELECT e.fname, e.lname, ROUND(SUM(DATEDIFF( IF(ed.leaving_date is null or ed.leaving_date = '' or ed.leaving_date='0000-00-00', CURRENT_DATE(), ed.leaving_date), ed.joining_date ))/365,0) AS Diff from employees e INNER JOIN employee_deatils ed ON e.id=ed.eemp_id group by ed.eemp_id it shows 2 records one with 0 and 3 years. But how to compare this with entered minimum years i am not getting. Not getting where to put Where condition with =3 years
  3. I could't get the solution for this. How can it get this value into a variable?
  4. @Barand Thanks, the logic worked but i have used this code. Now i want to get the data to variable in php thru javascript instead of displaying it based on id. as i do this <script> var res = "helloo"; </script> <?php $variable = "<script>document.write(res)</script>"; echo $variable; ?> it works. so as the same if it inside function onMessageArrived(r_message){ out_msg="Message received "+r_message.payloadString+"<br>"; out_msg=out_msg+"Message received Topic "+r_message.destinationName; //console.log("Message received ",r_message.payloadString); console.log(out_msg); document.getElementById("messages").innerHTML =out_msg; var topic=r_message.destinationName; if(topic=="house/outside-light") { document.getElementById("outside-light").innerHTML =r_message.payloadString; } if(topic=="house/outside-temperature") { var ot = r_message.payloadString; //document.getElementById("outside-temp").innerHTML =r_message.payloadString; } } <?php $test="<script>document.write(ot)</script>"; echo $test; ?> it won't work. Basically i want to get the data into a php variable. where i am going wrong, please suggest.
  5. I am storing a json data which come from server as a message for every 10 seconds. While displaying the data i have to separate it by its type. For single message i have done it but for multiple messages i am not getting how to separate each json message. i have attached the sql dump messages.txt Here is my code to print for single message include('includes/Connection.php'); $l1 = $con->prepare("SELECT msg, title FROM messages ORDER BY id DESC limit 1"); $l1->execute(); $cntmsg = $l1->rowCount(); foreach($l1 as $r1) { $m1 = $r1['msg']; $someJSON = $m1; $someArray = json_decode($someJSON, true); $pr1 = $someArray["data"]["commsettings"]; foreach($pr1 as $MyIndex => $MyValue){ echo $MyValue["name"]; } } It is working. But i should display for all the messages like this $l1 = $con->prepare("SELECT msg, title FROM messages ORDER BY id DESC limit 4"); $l1->execute(); It wont work with my logic. How can i separate the array , i am not getting.
  6. @Barand. Thanks. Atleast i found something to try on now. I will try this to integrate with my php code.
  7. Can you please any kind of tutorial or example for this to achieve? I couldn't get anything on this.
  8. I am developing a script for my client where i should be displaying data continuously coming from MQTT and my script is in PHP. Now i can publish and subscribe to topics but only after refreshing i can see the published data in my page. Do i need to use any script for this or how is it? Here is my subscribe page <?php require('phpMQTT.php'); $server = 'localhost'; // change if necessary $port = 1883; // change if necessary $username = '*****'; // set your username $password = '******'; // set your password $client_id = 'MyClient'; // make sure this is unique for connecting to sever - you could use uniqid() $mqtt = new Bluerhinos\phpMQTT($server, $port, $client_id); if(!$mqtt->connect(true, NULL, $username, $password)) { exit(1); } $mqtt->debug = true; $topics['xf/printservice/registration'] = array("qos"=>0, "function"=>"procmsg"); $mqtt->subscribe($topics,0); $start_time = time(); $done = 0; while (!$done && !hasTimedout() && $mqtt->proc()) { } $mqtt->close(); function procmsg($topic,$msg) { global $done; $done = 1; echo "Msg Recieved: ".date("r")."\nTopic:{$topic}\n$msg\n"; } function hasTimedout() { global $start_time; return (time() - $start_time > 10); } I am running this in localhost. How to keep displaying data without refreshing the page . is there any tutorial/script available ? please suggest.
  9. i am using dropzone to upload files to folder as well as database. It is working properly but after uploading page is not getting refreshed . I want to refresh the page. Not getting where to add the option. this is my form <form action="file_upload.php" class="dropzone"> <div> <strong>Drop files here or click to upload.</strong> </div> </form> And here are the options in dropzon.js Dropzone.prototype.defaultOptions = { url: null, method: "post", withCredentials: false, parallelUploads: 2, uploadMultiple: false, maxFilesize: 256, paramName: "file", createImageThumbnails: true, maxThumbnailFilesize: 10, thumbnailWidth: 120, thumbnailHeight: 120, filesizeBase: 1000, maxFiles: null, params: {}, clickable: true, ignoreHiddenFiles: true, acceptedFiles: null, acceptedMimeTypes: null, autoProcessQueue: true, autoQueue: true, addRemoveLinks: false, previewsContainer: null, hiddenInputContainer: "body", capture: null, renameFilename: null, dictDefaultMessage: "Drop files here to upload", dictFallbackMessage: "Your browser does not support drag'n'drop file uploads.", dictFallbackText: "Please use the fallback form below to upload your files like in the olden days.", dictFileTooBig: "File is too big ({{filesize}}MiB). Max filesize: {{maxFilesize}}MiB.", dictInvalidFileType: "You can't upload files of this type.", dictResponseError: "Server responded with {{statusCode}} code.", dictCancelUpload: "Cancel upload", dictCancelUploadConfirmation: "Are you sure you want to cancel this upload?", dictRemoveFile: "Remove file", dictRemoveFileConfirmation: null, dictMaxFilesExceeded: "You can not upload any more files.", accept: function(file, done) { return done(); }, init: function() { return noop; }, forceFallback: false, not getting where can i put the function location.reload()
  10. Yes, I got the answer. I modified query like this SELECT mid, mod_name, parent_id, link FROM modules m JOIN module_access ma ON (m.mid=ma.page_id OR ma.page_id=m.parent_id) WHERE ma.user=1 ORDER BY m.mid Thanks a lot @Barandfor your valuable time and patience.
  11. My Query return This is how it displays <!DOCTYPE html> <html lang="en"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8"> <meta name="generator" content="PhpED 19.5 (Build 19523, 64bit)"> <meta name="author" content="Barand"> <meta name="creation-date" content="08/11/2021"> <title>Example</title> <style type='text/css'> li { padding: 8px; } .li0 { margin-left: 8px; } .li1 { margin-left: 28px; } .li2 { margin-left: 48px; } </style> </head> <body> <ul> <li class='li0'><a href='#'> Sales </a> </li> <li class='li0'><a href='#'> Finance </a> </li> </ul> </body> </html> As it joins with the mid page_id from modules and module_access respectively, it wont display those ids which is not there in module_access table . So it is not getting displayed, as module_access table has only 1,3 ids which matches with mid from modules table.
  12. @Barand I tried the same <?php //$items = array(); $res = $con->prepare("SELECT mid, mod_name, parent_id, link FROM modules m JOIN module_access ma ON m.mid=ma.page_id WHERE ma.user=? ORDER BY m.mid"); $res->execute([$uID]); $mods = []; foreach ($res as $row) { $mods[$row['parent_id']][] = $row; } function showMenu(&$arr, $parent = 0, $level = 0) { if (!isset($arr[$parent])) return; echo "<ul>\n"; foreach($arr[$parent] as $rec) { echo "<li class='li$level'><a href='{$rec['link']}'> {$rec['mod_name']} </a>\n"; if (isset($arr[$rec['mid']])) showMenu($arr, $rec['mid'], $level+1); echo "</li>\n"; } echo "</ul>\n"; } showMenu($mods, 0); ?> But it shows only module names, not the sub-items under that.
  13. @BarandSorry for my mistake, I couldn't edit above post. in my module_access table, i have only module ids like this id| page_id | user 1 | 1 | 1 2 | 3 | 1 So, when i join , it shows only Sales and Finance as below. I want to display the sub items also. Sales Finance
  14. I have a small php script for crm. i have designed it by module wise. Admin can grant access to each module and sub-items under that modules. 1st step: admin will select modules(Sales, Purchase, Finance) for which he has to give access to a particular user and save the module ids in module_access table. 2nd step : only selected module's sub-items will display to admin , in which he can select to give access 1st step is done. but in 2nd step i am not able to display only selected modules with the sub-items. Here is the table where i stored my data. module table mid | mod_name | parent_id | link 1 | Sales | 0 | # 2 | Purchase | 0 | # 3 | Finance | 0 | # 4 | Clients | 1 | clients.php 5 | Quotes | 1 | quotes.php 6 | Vendors | 2 | vendors.php 7 | POs | 2 | pos.php 8 | Invoices | 3 | invoices.php 9 | Taxes | 3 | taxes.php 10 | Expense | 3 | expenses.php module_access table id| page_id | user 1 | 1 | 1 2 | 3 | 1 3 | 4 | 1 4 | 9 | 1 5 | 10 | 1 user is from another table users where i store user info In this example i want to display like this Sales Clients (with a checkbox) Finance Taxes (with a checkbox) Expense (with a checkbox) I tried like this <?php $items = array(); $res = $con->prepare("SELECT m.mid, m.mod_name, m.parent_id, ma.id, ma.page_id, ma.user FROM modules m INNER JOIN module_access ma ON m.mid=ma.page_id WHERE ma.user=? ORDER BY m.mid"); $res->execute([$uID]); foreach($res as $row) { $items[$row['parent_id']][] = $row; } function showMenu($items, $parent = null) { $index = $parent == null ? '0' : $parent; if (empty($items[$index])) { return; } echo '<ul', $parent == null ? ' id="subitems" ... ' : '', '>'; foreach ($items[$index] as $child) { echo '<li rel="', $child['mid'], '">', htmlentities($child['mod_name']); showMenu($items, $child['mid']); echo '</li>'; } echo '</ul>'; } showMenu($items); ?> But it displays like this Sales Finance I am not getting how to query this from database.
  15. I am adding line items in my invoice script, while adding i validate the data. if validation fails, it will display error message with entered data filled in the form. If it clears the validation, data gets submitted to database and displays the same . Here i can add many line items, so this process should keep repeating. Everything is working fine. But when the form submits it should display error in one place and display the submitted data in other place. Here is my form <form action="" method="post"> <div class="form-row"> <div class="col-md-4 mb-30"> <label for="validationDefault01">Select Customer</label> <select name="customer" class="form-control" id="validationDefault01" required> <option value=""></option> <?php $c1 = mysqli_query($con, "SELECT * FROM customers WHERE status='Active'") or die (mysqli_error($con)); while($c2 = mysqli_fetch_array($c1)) { ?> <option value="<?php echo $c2["cid"]; ?>" <?php if($c2["cid"] == $_POST['customer'] ) { echo "selected"; } ?> ><?php echo $c2["name"]; ?></option> <?php } ?> </select> </div> <div class="col-md-4 mb-30"> <label for="validationDefault02">Date</label> <input type="text" class="form-control" name="edate" id="datepicker" value="<?php echo isset($_POST["edate"]) ? $_POST["edate"] : $today; ?>" required /> </div> </div> <!-- line item --> <div class="table-responsive"> <table class="table table-active table-bordered table-sm"> <thead class="thead-active"> <tr> <th>Name</th> <th>Description</th> <th>UOM</th> <th>Price</th> <th>Stock</th> <th>Qty</th> </tr> </thead> <tr> <td><input type="text" id="productname" name="productname" value="<?php echo isset($_POST["productname"]) ? $_POST["productname"] : ''; ?>" required ></td> <input type="hidden" id="productcode" name="productcode" value="<?php echo isset($_POST["productcode"]) ? $_POST["productcode"] : ''; ?>" /> <td><textarea id="description" name="description"><?php echo isset($_POST["description"]) ? $_POST["description"] : ''; ?></textarea></td> <td><select name="uom" id="uom"> <?php $su1 = mysqli_query($con, "select * from uom"); while($su2 = mysqli_fetch_array($su1)) { ?> <option value="<?php echo $su2["uom_name"]; ?>" <?php if($su2["uom_name"] == $_POST['uom'] ) { echo "selected"; } ?> ><?php echo $su2["uom_name"]; ?></option> <?php } ?> </select> </td> <td><input type="text" required id="price" name="price" value="<?php echo isset($_POST["price"]) ? $_POST["price"] : ''; ?>" /></td> <td><input type="text" readonly id="stock" name="stock" value="<?php echo isset($_POST["stock"]) ? $_POST["stock"] : ''; ?>" /></td> <td><input type="text" required id="quantity" name="quantity" value="<?php echo isset($_POST["quantity"]) ? $_POST["quantity"] : ''; ?>" /></td> </tr> </table> <!-- line item ends---> <div class="form-row"> <div class="col-md-4 mb-30"> <input name="add" class="btn btn-success" type="submit" value="Add" /> </div> </div> </form> form submission <?php if(isset($_POST['add'])) { $customer = $_POST['customer']; $edate1 = $_POST['edate']; $edate = date('Y-m-d', strtotime((str_replace('/','-',$edate1)))); $pname = $_POST['productname']; $pcode = $_POST['productcode']; $uom = $_POST['uom']; $price = $_POST['price']; $quantity = $_POST['quantity']; $pc = mysqli_query($con, "SELECT min_price FROM items WHERE item_id=".$pcode."") or die (mysqli_error($con)); $prow = mysqli_fetch_array($pc); // This error part should be displayed inside <div id="error"></div> which is above the form if($price<$prow['min_price']) { echo '<div class="alert alert-inv alert-inv-danger alert-wth-icon alert-dismissible fade show" role="alert"> <span class="alert-icon-wrap"><i class="zmdi zmdi-bug"></i></span> Price should not be lesser than minimum price defined. <button type="button" class="close" data-dismiss="alert" aria-label="Close"> <span aria-hidden="true">×</span> </button> </div>'; } else { //data gets inserted into invoice table and displays submited data in table format // this part should be displayed below the form inside <div id="success"></div> } } Here i am not getting how to define that displays.
  16. <script type="text/javascript"> $('#addnameform').on('submit', function(e){ e.preventDefault(); var data = new FormData(); var selects = e.target.querySelectorAll(".form-control"); var values = []; for (var i = 0; i < selects.length; i++) { if (selects[i].value != 0) { values.push([selects[i].name, selects[i].value]) }; }; if (values.length) { values.forEach(function(val) { data.append(val[0], val[1], val[2], val[3], val[4], val[6]) alert(val[0]); }) var request = new XMLHttpRequest(); request.open("POST", "/echo/js/") request.onload = function() { values = []; console.log(data); for(prop of[...data]) { console.log(prop) } } request.send(data) } }); </script> is it right? now am not getting that error, but nothing is the output
  17. Getting this error ReferenceError: $ is not defined $('#addnameform').on('submit', function(e){
  18. Instead of form, u want me to go by form name???? <form method="post" action="" id="addnameform"> $("#addnameform").submit(function(e) { e.preventDefault(); like this?
  19. I have a form with 6 <select> options. All <select> filed will have same values but with different names. Like this: <form action="" method="post"> <select name="var1" class="form-control"> <option value="0">0</option> <option value="10">10</option> <option value="20">20</option> <option value="50">50</option> <option value="100">100</option> </select> <select name="var2" class="form-control"> <option value="0">0</option> <option value="10">10</option> <option value="20">20</option> <option value="50">50</option> <option value="100">100</option> </select> <input type="submit" name="submit" value="Submit"/> </form> <?php if(isset($_POST['submit'])) { include ('connect.php') ; include('admin_auth.php'); $var1 = $_POST['var1']; $var2 = $_POST['var2']; $var3= $_POST['var3']; // till $var6 $var11 = (mt_rand(1,3)); $var12 = rand(4,6); $var13 = mt_rand(1,6); // Here i should get only those variables n values which are greater than 0 } I am submitting these information to the same page, But before submit is it possible to filter those variables which are greater than 0? I want to POST only those variables which has value greater than 0. How can i do it? In the same page, i want to compare these values with the 3 random numbers which will generate when submit button is clicked. I tried doing like this using like this <script> var form = document.querySelector("form"); form.addEventListener("submit", function(e) { e.preventDefault(); var data = new FormData(); var selects = e.target.querySelectorAll(".form-control"); var values = []; for (var i = 0; i < selects.length; i++) { // if `select` `.value` is not `0`, // add to `values` array` if (selects[i].value != 0) { values.push([selects[i].name, selects[i].value]) }; }; // if `values` array contains items // append items to `FormData` object if (values.length) { values.forEach(function(val) { data.append(val[0], val[1]) alert(val[0]); }) var request = new XMLHttpRequest(); request.open("POST", "/echo/js/") request.onload = function() { values = []; console.log(data); // log values posted for (prop of [...data]) { console.log(prop) } } request.send(data) } }); </script> But nothing is happening, i tried to debug with Firebug, it shows TypeError: form is null form.addEventListener('submit', function(evt) { Can somebody help me in this?
  20. @ginerjm: Thank you, It got resolved! I did like this if(isset($_POST['submit'])) { $stk = $_POST['stockid']; $N = COUNT($_POST['chk']) ; for($i=0; $i<$N; $i++) { $color = $_POST['Color'][$i]; $size = $_POST['Size'][$i]; $cost = $_POST['Cost'][$i]; $selling_price = $_POST['Selling_price'][$i]; $opening_stock = $_POST['Opening_stock'][$i]; $sql1 = "INSERT INTO itemarticles (stk_code, color, size, cost, selling_price, opening_stock) VALUES ('".$stk."', ".$color.", ".$size.", ".$cost.", ".$selling_price.", ".$opening_stock.")"; $result = DB_query($sql1,$db);
  21. Hi, I am generating set of data input elements using json and jquery, But i am not able to add the counter to it, so that i can submit them into database. Here is my code echo '<form method="post" action="' . htmlspecialchars($_SERVER['PHP_SELF'],ENT_QUOTES,'UTF-8') . '" >'; echo '<div>'; echo '<input type="hidden" name="FormID" value="' . $_SESSION['FormID'] . '" />'; echo '<br />'; ?> <p> <input type="button" value="Add Attributes" onClick="addRow('dataTable')" /> <input type="button" value="Remove Attributes" onClick="deleteRow('dataTable')" /> <p>(All acions apply only to entries with check marked check boxes only.)</p> </p> <table id="dataTable" class="selection"> <tbody> <tr> <p> <td><input type="checkbox" required="required" name="chk[]" checked="checked" /></td> <td> <label for="Color">Select Color</label> <select id="Color" name="Color[]" required="required"> <?php $sql = "SELECT * FROM itemcolor"; $result = DB_query($sql,$db); while($myrow = DB_fetch_array($result)) { ?> <option value="<?php echo $myrow['color_id']; ?>"><?php echo $myrow['color']; ?></option> <?php } ?> </select> </td> <td> <label for="Size">Select Size</label> <select id="Size" name="Size[]" required="required"> <?php $sql = "SELECT * FROM itemsizes"; $result = DB_query($sql,$db); while($myrow = DB_fetch_array($result)) { ?> <option value="<?php echo $myrow['size_id']; ?>"><?php echo $myrow['size']; ?></option> <?php } ?> </select> </td> <td> <label>Cost Price</label> <input type="text" required="required" name="Cost[]"> </td> <td> <label for="Sale">Selling Price</label> <input type="text" required="required" name="Selling_price[]"> </td> <input type="hidden" name="stockid" value="<?php echo $stockID; ?>" /> <td> <label for="Stock">Opening Stock</label> <input type="text" required="required" name="Opening_stock[]"> </td> </p> </tr> </tbody> </table> <div class="clear"></div> <?php echo '<br /><div class="centre"><input type="submit" name="submit" value="' . _('Accept') . '" /><input type="submit" name="Cancel" value="' . _('Cancel') . '" /></div>'; echo '</div> </form>'; After submitting if(isset($_POST['submit'])) { $stk = $_POST['stockid']; foreach ($_POST['chk'] as $k) { $color = $_POST['Color'][$k]; $size = $_POST['Size'][$k]; $cost = $_POST['Cost'][$k]; $selling_price = $_POST['Selling_price'][$k]; $opening_stock = $_POST['Opening_stock'][$k]; $sql1 = "INSERT INTO itemarticles (stk_code, color, size, cost, selling_price, opening_stock) VALUES ('".$stk."', ".$color.", ".$size.", ".$cost.", ".$selling_price.", ".$opening_stock.")"; $result = DB_query($sql1,$db); if($result) { header("location:StockAttributes.php?Success=1"); } } } But to put like , foreach ($_POST['chk'] as $k) <input type="text" required="required" name="Opening_stock[$counter]"> In script, function addRow(tableID) { var table = document.getElementById(tableID); var rowCount = table.rows.length; if(rowCount < 30){ // limit the user from creating fields more than your limits var row = table.insertRow(rowCount); var colCount = table.rows[0].cells.length; for(var i=0; i<colCount; i++) { var newcell = row.insertCell(i); newcell.innerHTML = table.rows[0].cells[i].innerHTML; } }else{ alert("Maximum Attributes per Item is 30."); } } function deleteRow(tableID) { var table = document.getElementById(tableID); var rowCount = table.rows.length; for(var i=0; i<rowCount; i++) { var row = table.rows[i]; var chkbox = row.cells[0].childNodes[0]; if(null != chkbox && true == chkbox.checked) { if(rowCount <= 1) { // limit the user from removing all the fields alert("Cannot Remove all the Attributes."); break; } table.deleteRow(i); rowCount--; i--; } } } Can someone please guide me in doing this please
  22. Kindly help me with this footer section... I am not able to do it. . Please
  23. @Barand: Yup. I got It! But i am not getting how to print the footer details in this format . Can u please give me an idea in this.....
  24. Whenever u have time please have a look into it. Thanks
  25. @ Barand: Thanks . I got it why its not displaying. Actually I am getting. Quote was mission for id in where clause. Can you please suggest me how to ass dynamic contents in header?
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.