Jump to content

FooKelvin

Members
  • Posts

    138
  • Joined

  • Last visited

Profile Information

  • Gender
    Not Telling

FooKelvin's Achievements

Regular Member

Regular Member (3/5)

0

Reputation

3

Community Answers

  1. 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.
  2. Sorry for the misalignment. Current Output: Database table and expect result: foreach.txt
  3. 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. 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.
  5. Thanks! now it successfully convert to timestamp format But yet, the date not able to show up. hmm...let me figure it out..
  6. 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
  7. $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"}}]}
  8. 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
  9. 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);
  10. 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.
  11. Please Ignore it. i manage to make it correct..
  12. 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..
  13. Hi Jacquest1, Im testing your code as well..is working actually..
  14. 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.
×
×
  • 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.