Jump to content

Barand

Moderators
  • Posts

    24,566
  • Joined

  • Last visited

  • Days Won

    822

Everything posted by Barand

  1. No, No, No! For the last time (I'll type it slowly), NOT the order id You need the id of the individual order detail record name="quantity[$result->id]"
  2. The time-limit for editing the post will have expired by now. Post your current code
  3. do you now have name="quantity[$result->id]" and same for the other order detail fields?
  4. You need to be using tbl_orderdetail.id as the indexes for the field names
  5. Add a hidden field to your form containing the id of whatever they are commenting on. Save this id, comment and user_id to a comments table. The id will allow you to relate the comment to the original.
  6. NOT the order_id. That would give the fields for every detail record the same id. You want the id from the order detail records
  7. Separate tables will be a PIA when you need to query for results across regions. EG How many submissions have we had in the last three months?
  8. At the moment you have name='productname[]'. I am suggesting you change that to name='productname[$det_id]' where $det_id is the id of the order detail record. Do this for all fields to tie them to the same record. That will be the key of the POSTed data foreach ($_POST['quantity'] as $ord_det_id => $quantity) {
  9. This will do it using CSS $sql = "SELECT timeslot , client , TIMESTAMPDIFF(HOUR, timeslot, NOW()) as elapsed FROM timeslots"; $res = $db->query($sql); $rows = ''; while (list($ts, $cl, $el) = $res->fetch_row()) { $class = $el >= 20 ? 'class="blink"' : ''; $rows .= "<tr><td>$cl</td><td $class>$ts</td></tr>\n"; } ?> <html> <head> <title>Example Flashing</title> <style type='text/css'> /* The animation code */ @keyframes flash { from {background-color: red;} to {background-color: white;} } /* The element to apply the animation to */ td.blink { width: 100px; height: 100px; background-color: white; animation: flash 1s infinite; } </style> </head> <body> <table border="1"> <tr><th>Client</th><th>Time</th></tr> <?=$rows?> </table> </body> </html>
  10. Use the order detail record ids as the array indexes for the field names E.G. name="quantity[$det_id]" name="productname[$det_id]" Then you can use those ids to update the associated detail records foreach ($_POST['quantity'] as $ord_det_id => $quantity) { $productname = $_POST['productname'][$ord_det_id]; ... $sql = "UPDATE tbl_orderdetail SET productname='$productname', quantity=$quantity, ... WHERE order_detail_id = $ord_det_id"; }
  11. You still only need the id, then when the form is posted INSERT INTO table2 (book_id, name, cover, pageno) SELECT book_id, name, cover, pageno FROM table1 WHERE book_id = $posted_id
  12. You could SELECT ... , Created_date , TIMESTAMPDIFF(HOUR, Created_Date, NOW() ) as elapsed FROM ... then apply flashing when odbc_result($result, "elapsed") >= 20
  13. A database should hold data in a single place and the only things that are replicated in other tables are key values. So the only item you transfer to table2 should be the book_id. You get the book name etc by referencing the book table via the id value.
  14. QOC, You seem to be misinterpreting the single quote restriction. This applies when the entire string is in single quotes. Single quotes inside a double quoted string do not turn off variable parsing. $myvar = 'abc'; echo "The value in \$myvar is '$myvar' "; //--> The value in $myvar is 'abc'
  15. So you want to transfer three columns of data from table1 to table 2? Why do you have form involved? They are hidden fields so the user cannot see or edit them?
  16. File 1 <a href="file2.php">Download newfies</a> File2.php (the download code goes in a file of its own) <?php $sql = 'SELECT * FROM newfies'; sql2csv($db_mysqli, $sql, $filename='myNewfile.csv', $headings=0); function sql2csv($db_mysqli, $sql, $filename='', $headings=0) { if (!$filename) $f = 'download_' . date('ymdhi') . '.csv'; else $f = $filename; $fp = fopen('php://output', 'w'); // so you can fputcsv to STDOUT if ($fp) { $res = $db_mysqli->query($sql); if ($res) { header('Content-Type: text/csv'); header('Content-Disposition: attachment; filename="'.$f.'"'); header('Pragma: no-cache'); header('Expires: 0'); $row = $res->fetch_assoc(); if ($headings) { fputcsv($fp, array_keys($row),'|'); } do { fputcsv($fp, $row); } while ($row = $res->fetch_assoc()); } else echo "Error in query"; fclose($fp); } } ?>
  17. Forget about your "solution" for now - what is it you want to achieve?
  18. What's with all the @variables? SELECT item_id , SUM(positive) as totpos , SUM(neutral) as totneu , SUM(negative) as totneg , COUNT(*) as tot , SUM(positive + neutral - negative)/COUNT(*)*100 as pcent FROM user_feedback GROUP BY item_id;
  19. File 1 <a href="file2.php">Download newfies</a> File2.php (the download code goes in a file of its own) <?php $sql = 'SELECT * FROM newfies'; sql2csv($db_mysqli, $sql, $filename='myNewfile.csv', $headings=0); function sql2csv($db_mysqli, $sql, $filename='', $headings=0) { if (!$filename) $f = 'download_' . date('ymdhi') . '.csv'; else $f = $filename; $fp = fopen('php://output', 'w'); // so you can fputcsv to STDOUT if ($fp) { $res = $db_mysqli->query($sql); if ($res) { header('Content-Type: text/csv'); header('Content-Disposition: attachment; filename="'.$f.'"'); header('Pragma: no-cache'); header('Expires: 0'); $row = $res->fetch_assoc(); if ($headings) { fputcsv($fp, array_keys($row),'|'); } do { fputcsv($fp, $row); } while ($row = $res->fetch_assoc()); } else echo "Error in query"; fclose($fp); } } ?>
  20. You don't show your call to the function. Is this code in a file of its own?
  21. This methods creates and downloads in a single operation http://forums.phpfreaks.com/topic/296581-how-i-can-i-let-user-to-download-a-data-from-query-in-mysql/?do=findComment&comment=1512967
  22. I used MySqli because that's what I have, but it should be easily converted for sqlsrv. Here's the method /***************************************************** * first you need to get the column headings * and create array to store responses for * each question ******************************************************/ $sql = "SELECT DISTINCT name FROM kelvin ORDER BY name"; $names = array(); $res = $db->query($sql); while ($row = $res->fetch_assoc()) { $names[] = $row['name']; } $tableHeads = "<tr><th>Question</th><th>" . join('</th><th>', $names) . "</th></tr>\n"; $newArray = array_fill_keys($names,''); // create blank array /***************************************************** * then you process the table data * storing the answers for each name in the array. * * output the array for each question when the question * value changes, then start with a new array for the new * question ******************************************************/ $sql = "SELECT question, name, answer FROM kelvin ORDER BY question"; $qarray = $newArray; // new array to store answers to question $currq = ''; // store the current question $tableData = ''; $res = $db->query($sql); while ($row = $res->fetch_assoc()) { if ($row['question'] != $currq) { // change of question? if ($currq) { // have we a question yet? $tableData .= "<tr><td>$currq</td><td>"; $tableData .= join('</td><td>', $qarray) . "</td></tr>\n"; } $currq = $row['question']; // store new question $qarray = $newArray; // reset the array } $qarray[$row['name']] = $row['answer']; // store the answer by name } // output the stored array for the final question $tableData .= "<tr><td>$currq</td><td>"; $tableData .= join('</td><td>', $qarray) . "</td></tr>\n"; ?> <table border='1'> <?=$tableHeads?> <?=$tableData?> </table> My data mysql> SELECT * FROM test.kelvin; +----+---------+------------+--------------------+--------------------+ | id | name | questionid | question | answer | +----+---------+------------+--------------------+--------------------+ | 1 | Foo | 1000 | How are you? | I'm Fine | | 2 | Foo | 1001 | What is Your name? | My Name is Foo | | 3 | Ben | 1000 | How are you? | I Feel sick | | 4 | Ben | 1001 | What is Your name? | My name is Ben | | 5 | Charlie | 1001 | What is Your name? | My name is Charlie | +----+---------+------------+--------------------+--------------------+ Results attached
  23. The connection is to the server so if the databases are on the same server then a single connection is sufficient. You can, if you want, mix databases in a single query if on the same server SELECT ... FROM database1.tableA as a INNER JOIN database2.tableB as b
  24. Also note the the use of session_register() was replaced by $_SESSION in December 2001.
  25. Of course it's for the select box - that's what you said your problem was
×
×
  • 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.