Jump to content

FooKelvin

Members
  • Content Count

    138
  • Joined

  • Last visited

Everything posted by FooKelvin

  1. I would like to have this +3 apply when the paymentterm if is less than 45. So the current code is using case statement. SELECT SUM(sblPOAmount) AS totalPOAmt, case when paymentTerm = '45 Days' then DATENAME(Day, DATEADD(day, SUBSTRING(paymentTerm, 1, 2) + 3, SBLInvoiceDate)) else DATENAME(Day, DATEADD(day, SUBSTRING(paymentTerm, 1, 2) + 0, SBLInvoiceDate)) end FROM [A_Sys].[dbo].[Eventtbl] WHERE DATENAME(MONTH, DATEADD(day,SUBSTRING(paymentTerm, 1, 2)+3,SBLInvoiceDate))='June' AND DATENAME(YEAR, DATEADD(day,SUBSTRING(paymentTerm, 1, 2)+3,SBLInvoiceDate))='2017' Group By paymentTerm,SBLInvoiceDate The Sum having multiple result due to "Group By", but if i run it without Group By , it will have error message. Please help
  2. Hi All, I have generate a form which contain the id and name. the name and id i use php foreach them from database, to make it simple, im just copy the HTML and paste it here. each of them have individual approval status and remarks. once submit, it should update individual rows. I am using ajax to post. My current code. <html> <body> <hr> <section> <h3 id="title454"> Requestor </h3> </section> <form id="form" action="" method="post"> <table> <tr> <th>Employee Name</th> <th>Employee ID</th> <th>Remark</th> <th>Action</th> </tr> <tr><td>Kelvin</td><td>EE123</td><td><textarea name="remark[]"></textarea></td><td><select name="status[]"><option disabled value="">-Pending-</option><option value="Approved">Approve</option><option value="Reject">Reject</option></select><br></td></tr><tr><td>James</td><td>EE156</td><td><textarea name="remark[]"></textarea></td><td><select name="status[]"><option disabled value="">-Pending-</option><option value="Approved">Approve</option><option value="Reject">Reject</option></select><br></td></tr></table> <hr> <table> <ul> <section> <h3 id="title454"> 1st Level Approval </h3> </section> <li> <label>Amount Approved</label> <span> <select name="amount-approved"> <option disabled value="" selected>-Select-</option> <option>50%</option> <option>100%</option> </select> </span> </li> </ul> </table> <input id="submit" type="button" name="submit" value="submit"> </form> <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.3/jquery.min.js"></script> <script> $(document).ready(function(){ // click on button submit $("#submit").on('click', function(){ // send ajax $.ajax({ url: 'tier_one_submit_status.php', // url where to submit the request type : "POST", // type of action POST || GET dataType : 'json', // data type data : $("#form").serialize(), // post data || get data success : function(result) { // you can see the result from the console // tab of the developer tools console.log(result); }, error: function(xhr, resp, text) { console.log(xhr, resp, text); } }) }); }); </script> </body> </html> after click the submit button, i would like to update the data individually. Please help.
  3. FooKelvin

    Foreach no result

    I have a questions table and feedback table. I able to foreach the question header but not the feedback. My code as above: <?php $sql2 = "SELECT DISTINCT[question_id],[q_text] FROM [question]"; $ques = array(); $stmt2 = sqlsrv_query($conn, $sql2, $ques); while ($row = sqlsrv_fetch_array($stmt2, SQLSRV_FETCH_ASSOC)) { $ques[$row['question_id']] = $row['q_text']; } $sql = "SELECT [question_id], [Expr3],[Expr2] FROM [feedback] ORDER BY [Expr2] ASC"; $data = array(); $stmt = sqlsrv_query($conn, $sql); while (list($qid, $a, $eid) = sqlsrv_fetch_array($stmt, SQLSRV_FETCH_NUMERIC)) { if (!isset($data[$qid][$eid])) { $data[$qid][$eid] = $newArray2; } $data[$qid][$eid][] = $a; } ?> <div class="container"> <?php // produce table header echo "<table border='1' id='table2excel'>\n"; echo "<tr><th>Employee ID</th>"; // loop over array of questions for the header foreach ($ques as $question) { echo "<th>$question</th>"; } echo "</tr>\n"; foreach ($data as $qid => $question) { foreach ($question as $question => $replies) { echo "<tr><td>$question</td>"; foreach (array_keys($ques) as $q_id) { echo "<td>"; echo $replies[$q_id]; echo "</td>"; } echo "</tr>\n"; echo "</tr>\n"; } } echo "</table>\n"; Questions Table: question_id q_text 1 Do you Like Red Color? 02A Do you Like Yellow Color? 02B Do you Like Blue Color? 3 Do you Like Green Color? 4 What color you like among them? 5 Do you Like Purple Color? 6 Do you Like Gold Color? 7 Do you Like Rose Gold Color? 8 Do you Like Black Color? 9 Do you Like Orange Color? The question 4, might be multiple answer. Feedback Table: question_id Expr2 Expr3 1 EMP1001 Yes 02A EMP1001 No 4 EMP1001 Red 4 EMP1001 Yellow 4 EMP1001 Blue 5 EMP1001 No 6 EMP1001 No 3 EMP1001 Yes 02B EMP1001 Yes 7 EMP1001 Yes 8 EMP1001 Yes 9 EMP1001 Yes 1 EMP1002 Yes 02A EMP1002 No 4 EMP1002 Red 5 EMP1002 No 6 EMP1002 Yes 3 EMP1002 Yes 02B EMP1002 Yes 7 EMP1002 No 8 EMP1002 9 EMP1002 Yes Result: Employee ID Do you Like Red Color? Do you Like Yellow Color? Do you Like Blue Color? Do you Like Green Color? What color you like among them? Do you Like Purple Color? Do you Like Gold Color? Do you Like Rose Gold Color? Do you Like Black Color? Do you Like Orange Color? EMP1001 EMP1002 EMP1001 EMP1002 EMP1001 EMP1002 EMP1001 EMP1002 EMP1001 EMP1002 EMP1001 EMP1002 EMP1001 EMP1002 EMP1001 EMP1002 EMP1001 EMP1002 EMP1001 EMP1002 Expected Result: Employee ID Do you Like Red Color? Do you Like Yellow Color? Do you Like Blue Color? Do you Like Green Color? What color you like among them? Do you Like Purple Color? Do you Like Gold Color? Do you Like Rose Gold Color? Do you Like Black Color? Do you Like Orange Color? EMP1001 Yes No Yes Yes Red No No Yes Yes Yes EMP1001 Yes No Yes Yes Yellow No No Yes Yes Yes EMP1001 Yes No Yes Yes Blue No No Yes Yes Yes EMP1002 Yes No Yes Yes Red No Yes No Yes The question id no.4 will allow multiple choice to select, hence there will be multiple feedback for that particular question. foreach.txt
  4. FooKelvin

    Foreach no result

    Hi mac, yes...it is similar questions, but due to echo implode('<hr>',$replies[$q_id]); // note: this works correctly if there is a single reply, the result is just the single array element by itself when i export to excel, it automatically merge the table in excel, which is good.. some how i face problem when i Vloopup in excel file, so i am thinking to split them when it has multiple feedback.
  5. FooKelvin

    Foreach no result

    Sorry for the misalignment. Current Output: Database table and expect result: foreach.txt
  6. FooKelvin

    JQuery Control Drop down list

    Hi All, Would like to ask whether can the drop down list in html can be control by Jquery with this condition? Each question can only rate for 3 times, the following drop box for that question should disable and not allow to make any rating. here is my HTML code: <div> <span id="questionnaire-question">Q1)&nbspPlease QuestionA</span> <table> <tr style="width: 365px;"> <td><label>A1</label></td> <td> <select name="ranking[13]" class="02A" group="02A"> <option value="" >Please Rank</option> <option>1</option> <option>2</option> <option>3</option> </select> </td> </tr> <tr style="width: 365px;"> <td><label>A2</label></td> <td> <select name="ranking[14]" class="02A" group="02A"> <option value="" >Please Rank</option> <option>1</option> <option>2</option> <option>3</option> </select> </td> </tr> <tr style="width: 365px;"> <td><label>A3</label></td> <td> <select name="ranking[15]" class="02A" group="02A"> <option value="" >Please Rank</option> <option>1</option> <option>2</option> <option>3</option> </select> </td> </tr> <tr style="width: 365px;"> <td><label>A4</label></td> <td> <select name="ranking[16]" class="02A" group="02A"> <option value="" >Please Rank</option> <option>1</option> <option>2</option> <option>3</option> </select> </td> </tr> </table> </div> <div> <span id="questionnaire-question">Q2)&nbspPlease QuestionB</span> <table> <tr style="width: 365px;"> <td><label>B1</label></td> <td> <select name="ranking[21]" class="03A" group="03A"> <option value="" >Please Rank</option> <option>1</option> <option>2</option> <option>3</option> </select> </td> </tr> <tr style="width: 365px;"> <td><label>B2</label></td> <td> <select name="ranking[22]" class="03A" group="03A"> <option value="" >Please Rank</option> <option>1</option> <option>2</option> <option>3</option> </select> </td> </tr> <tr style="width: 365px;"> <td><label>B3</label></td> <td> <select name="ranking[23]" class="03A" group="03A"> <option value="" >Please Rank</option> <option>1</option> <option>2</option> <option>3</option> </select> </td> </tr> <tr style="width: 365px;"> <td><label>B4</label></td> <td> <select name="ranking[28]" class="03A" group="03A"> <option value="" >Please Rank</option> <option>1</option> <option>2</option> <option>3</option> </select> </td> </tr> </table> </div> Thank You.
  7. FooKelvin

    PHP JSON Encode Date Format

    Hi All, I am using JTable Plug in and using PHP code as my server language. The plug in requires json encode in this format, ** please ignore other data. except for "RecordDate" ** { "Result":"OK", "Records":[ {"PersonId":1,"Name":"Benjamin Button","Age":17,"RecordDate":"\/Date(1320259705710)\/"}, {"PersonId":2,"Name":"Douglas Adams","Age":42,"RecordDate":"\/Date(1320259705710)\/"}, {"PersonId":3,"Name":"Isaac Asimov","Age":26,"RecordDate":"\/Date(1320259705710)\/"}, {"PersonId":4,"Name":"Thomas More","Age":65,"RecordDate":"\/Date(1320259705710)\/"} ] } What i have for my output is, { "Result": "OK", "TotalRecordCount": 1, "Records": [ {"Row": "1","emp_id": "Nhhh","course1": {"date": "2017-01-06 00:00:00","timezone_type": 3,"timezone": "Asia\/Brunei"} }] } Im currently using datetime as my data type in my database (SQL Server), and the output is empty due to wrong json date format. thanks for the help.
  8. FooKelvin

    PHP JSON Encode Date Format

    Thanks! now it successfully convert to timestamp format But yet, the date not able to show up. hmm...let me figure it out..
  9. FooKelvin

    PHP JSON Encode Date Format

    Yup, I tried to put it the php class like this, am i put in a correct place? class JsonDateTime extends DateTime implements JsonSerializable { //<== Getting Red line error "JsonDateTime" public function __construct(DateTime $dt) { parent::__construct($dt->format("r")); } public function jsonSerialize() { return "/Date(" . $this->getTimestamp() . ")/"; } } $result = sqlsrv_query( $conn, "SELECT COUNT(*) AS RecordCount FROM [A_Sys].[dbo].[testdate]"); $row = sqlsrv_fetch_array($result, SQLSRV_FETCH_ASSOC); The browser show HTTP ERROR 500
  10. FooKelvin

    PHP JSON Encode Date Format

    $result = sqlsrv_query( $conn, "SELECT COUNT(*) AS RecordCount FROM [A_Sys].[dbo].[testdate]"); $row = sqlsrv_fetch_array($result, SQLSRV_FETCH_ASSOC); $recordCount = $row['RecordCount']; //Get records from database $result = "SELECT * FROM (SELECT ROW_NUMBER() OVER (ORDER BY [emp_id]) As Row, * FROM [A_Sys].[dbo].[testdate]) As PeopleWithRowNumbers WHERE Row >" . $_REQUEST["jtStartIndex"] . "AND Row <= " . $_GET['jtStartIndex'] ." + ". $_GET['jtPageSize'].""; $stmt = sqlsrv_query($conn, $result); //Add all records to an array $rows = array(); while($row = sqlsrv_fetch_array($stmt, SQLSRV_FETCH_ASSOC)) { $rows[] = $row; } //$recordCount = $row['RecordCount']; //Return result to jTable $jTableResult = array(); $jTableResult['Result'] = "OK"; $jTableResult['TotalRecordCount'] = $recordCount; $jTableResult['Records'] = $rows; print json_encode($jTableResult); This is my DB: emp_id course1 --------------------------- 1012345 1/5/2017 My Print JSON {"Result":"OK","TotalRecordCount":1,"Records":[{"Row":"1","emp_id":"1012345","course1":{"date":"2017-01-05 00:00:00","timezone_type":3,"timezone":"Asia\/Brunei"}}]}
  11. FooKelvin

    PHP JSON Encode Date Format

    The first sample code is from documentation, the second code sample is my own output.. Here is the link of documentation. the problem that i facing now is the date format. i cant get the exactly the date format in the documentation. which is converted to unix timestamp. Documentation => http://jtable.org/GettingStarted
  12. FooKelvin

    PHP JSON Encode Date Format

    this is my current php code. $rows = array(); while($row = sqlsrv_fetch_array($stmt, SQLSRV_FETCH_ASSOC)) { $rows[] = $row; // <= do you mean i need to convert it here? } //$recordCount = $row['RecordCount']; //Return result to jTable $jTableResult = array(); $jTableResult['Result'] = "OK"; $jTableResult['TotalRecordCount'] = $recordCount; $jTableResult['Records'] = $rows; print json_encode($jTableResult);
  13. Hi, i have my foreach loop codes here. What i trying to do is loop them out and list them with their own href link, but now the problem is, all of them are sharing href link. My Code: foreach ($data as $eid => $cdata) { $trows .= "<tr><td class='eid'>{$eid}</td>"; foreach ($cdata as $fc => $content) { $trows .= "<td><a href='#'>" . join(';<br>', $content) ."</a></td>"; } $trows .= "</tr>\n"; } Here is my output: After Inspect Element of HTML code: <tr><td class="eid">E1234</td><td><a href="#">A.pdf;<br>B.pdf;<br>C.xlsx</a></td></tr> Expected Output: <tr><td class="eid">E1234</td><td><a href="#">A.pdf</a>;<br><a href="#">B.pdf</a>;<br><a href="#">C.xlsx</a></td></tr>
  14. FooKelvin

    For Each Loop with their own a href

    Please Ignore it. i manage to make it correct..
  15. FooKelvin

    For Each Loop with their own a href

    This is my array: Array ( [name] => [events] => Array ( [0] =>A.doc [1] =>B.pdf [2] =>C.pdf ) ) when echo it out, there is one extra row in between. like this..
  16. FooKelvin

    For Each Loop with their own a href

    Hi Jacquest1, Im testing your code as well..is working actually..
  17. FooKelvin

    For Each Loop with their own a href

    Yup, my code currently able to join the array value in the same "td", but then i need them to be separate, cause i need to store their own href link.
  18. FooKelvin

    For Each Loop with their own a href

    Hi requinix, sorry, I dont get you..
  19. FooKelvin

    PHP JSON Encode

    Hi All, Here is my code, trying to encode the result from database. $stmt = sqlsrv_query($conn, $result); $data = array(); while ($row = sqlsrv_fetch_array($stmt, SQLSRV_FETCH_ASSOC)) { $data[] = $row; } //echo json_encode( $data ); $out = array(); foreach($data as $element) { $out[$element['category']][] = array($element['trainFunction']=> $element['value1']); } echo json_encode( $out ); Result of JSON Echo: {"November":[{"A":7},{"B":8},{"C":3},{"D":4}],"December":[{"A":1},{"B":2},{"C":1}]} Expected Output: { "November": [{ "A": 7, "B": 8, "C": 3, "D": 4 }], "December": [{ "A": 1, "B": 2, "C": 1 }] }
  20. FooKelvin

    PHP JSON Encode

    Yes Requinix, Thanks for the explanation, its really helps me!
  21. FooKelvin

    PHP JSON Encode

    Thanks Requinix, I have change to foreach($data as $element) { $out[$element['category']][$element['trainFunction']] = $element['value1']; } Output: {"November":{"Engineering":7,"Leadership & Soft Skills":8,"Lean":3,"Quality":4},"December":{"Engineering":2,"Leadership & Soft Skills":3,"Quality":1}} But i do not understand, "use array_values() on $out to strip off the outermost keys and turn it into a regular array. "
  22. FooKelvin

    PHP JSON Encode

    Update Expected Output: [{ "A": 7, "B": 8, "C": 3, "D": 4, "category": "November" }, { "A": 1, "B": 2, "C": 1, "category": "December" }]
  23. Hi, I have a list of tracking, separate by module. Example Certificate 1MS1 MS2 MS3 MS4 MS5 MS6 Certificate 2MS7 MS8 MS9 MS10 MS11 MS12 Each module have their own scoring. There is also another filed to track the status. In order to entitle for the certificate 1, they need to pass all the module under certificate 1. the passing condition >= 50. Eg: In order to get Certificate 1, the marks of MS1 - MS6 should >=50. What i facing now, i failed to sum the marks the status of certificate display in the wrong column. here is my code: $newarray = array(1 => array(), 2 => array(), 3 => array(), 4 => array(), 5 => array(), 6 => array(), 7 => array(), 8 => array(), 9 => array(), 10 => array(), 11 => array(), 12 => array()); $data = array(); $trows = ''; $sql = "SELECT eid,[Name] ,[course] ,[marks] ,[id] ,[courselvl] FROM [scview]"; $stmt = sqlsrv_query($conn, $sql); while (list($eid, $name, $course, $marks, $id, $courselvl,$a) = sqlsrv_fetch_array($stmt, SQLSRV_FETCH_NUMERIC)) { if (!isset($data[$eid])) { //$data[$eid][$qid] = $newArray2; $data[$eid]['name'] = $name; $data[$eid]['module'] = $newarray; } $item = $marks; $data[$eid]['module'][$id][] = $item; } foreach ($data as $id => $mdata) { $trows .= "<tr><td>{$mdata['name']}</td>"; foreach ($mdata['module'] as $id => $marks) { $trows .= "<td>" . join(';<br>', $marks) . "</td>"; } $trows .="<td>Entitle For Cert 1</td>"; $trows .="<td>Entitle For Cert 2</td>"; $trows .= "</tr>\n"; }; ?> <table border='1' id="example" style="width:100%"> <thead> <tr> <th>Name</th> <th>MS1</th> <th>MS2</th> <th>MS3</th> <th>MS4</th> <th>MS5</th> <th>MS6</th> <th>Certificate</th> <th>MS7</th> <th>MS8</th> <th>MS9</th> <th>MS10</th> <th>MS11</th> <th>MS12</th> <th>Certificate2</th> </tr> </thead> <tbody> <?php echo $trows; ?> </tbody> </table> </body> Here is my DB. I have 2 DB, and i join them. course table: id course 1 MS1 2 MS2 3 MS3 4 MS4 5 MS5 6 MS6 7 MS7 8 MS8 9 MS9 10 MS10 11 MS11 12 MS12 enrollment table: Name course marks eid Lim MS7 40 e2 Lim MS8 50 e2 Lim MS9 66 e2 Lim MS10 76 e2 Lim MS11 56 e2 Lim MS12 55 e2 Lim MS1 40 e2 Lim MS2 50 e2 Lim MS3 66 e2 Lim MS4 76 e2 Lim MS5 56 e2 Lim MS6 55 e2 Foo MS1 60 e1 Foo MS2 60 e1 Foo MS3 76 e1 Foo MS4 76 e1 Foo MS5 86 e1 Foo MS6 75 e1 Foo MS7 30 e1 Foo MS8 30 e1 Foo MS9 36 e1 Foo MS10 36 e1 Foo MS11 66 e1 Foo MS12 65 e1 After Join table, and i run the query Output: Name course marks id courselvl eid Lim MS7 40 7 MS7 e2 Lim MS8 50 8 MS8 e2 Lim MS9 66 9 MS9 e2 Lim MS10 76 10 MS10 e2 Lim MS11 56 11 MS11 e2 Lim MS12 55 12 MS12 e2 Lim MS1 40 1 MS1 e2 Lim MS2 50 2 MS2 e2 Lim MS3 66 3 MS3 e2 Lim MS4 76 4 MS4 e2 Lim MS5 56 5 MS5 e2 Lim MS6 55 6 MS6 e2 Foo MS1 60 1 MS1 e1 Foo MS2 60 2 MS2 e1 Foo MS3 76 3 MS3 e1 Foo MS4 76 4 MS4 e1 Foo MS5 86 5 MS5 e1 Foo MS6 75 6 MS6 e1 Foo MS7 30 7 MS7 e1 Foo MS8 30 8 MS8 e1 Foo MS9 36 9 MS9 e1 Foo MS10 36 10 MS10 e1 Foo MS11 66 11 MS11 e1 Foo MS12 65 12 MS12 e1 ############################################################################################### The output that display in browser: Expected Output: Thank You
  24. FooKelvin

    Foreach array (sum array + condition)

    Hi Barand, Sorry. i found where is going wrong. Your code words perfectly. there is because my data type using nvarchar, so the array include a lot of spaces. thanks again Barand.
  25. FooKelvin

    Foreach array (sum array + condition)

    Hi Barand, am i missed out anything? because the output show "completed only" I tried to understand the for loop : $certres = "Entitle for Cert $cert"; for ($lvl = 1; $lvl <= $cert; $lvl++) { echo "cert:".$cert; //<-- new added echo "level:".$lvl; //<-- new added if (min($studata[$lvl]) < 50) { $certres = 'Complete only'; break; } } i found that : cert:1 level:1cert:2 level:1
×

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.