Jump to content

Barand

Moderators
  • Posts

    24,588
  • Joined

  • Last visited

  • Days Won

    827

Everything posted by Barand

  1. You need to be using tbl_orderdetail.id as the indexes for the field names
  2. 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.
  3. 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
  4. 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?
  5. 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) {
  6. 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>
  7. 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"; }
  8. 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
  9. You could SELECT ... , Created_date , TIMESTAMPDIFF(HOUR, Created_Date, NOW() ) as elapsed FROM ... then apply flashing when odbc_result($result, "elapsed") >= 20
  10. 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.
  11. 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'
  12. 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?
  13. 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); } } ?>
  14. Forget about your "solution" for now - what is it you want to achieve?
  15. 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;
  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. You don't show your call to the function. Is this code in a file of its own?
  18. 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
  19. 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
  20. 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
  21. Also note the the use of session_register() was replaced by $_SESSION in December 2001.
  22. Of course it's for the select box - that's what you said your problem was
  23. Perhaps function priceFormat ($val, $currency) { $vi = intval($val); $dec = $currency=='€' ? ',' : '.'; if ($val == $vi) { return "$currency$vi"; } else { return sprintf('%s%d%s<small>%02.0f</small>', $currency,$vi,$dec,($val-$vi)*100); } } echo priceFormat(10.00, '£') . '<br>'; echo priceFormat(10.99, '£') . '<br>'; echo priceFormat(120.00, '€') . '<br>'; echo priceFormat(120.99, '€') . '<br>';
  24. data user_info books +--------------+----------+-------+ +----+-------+--------+ | user_info_id | username | title | | id | title | copies | +--------------+----------+-------+ +----+-------+--------+ | 1 | qqq | aaa | | 1 | aaa | 2 | | 2 | www | aaa | | 2 | bbb | 3 | | 3 | eee | bbb | | 3 | ccc | 2 | | 4 | fff | ccc | | 4 | ddd | 3 | | 5 | ggg | ccc | +----+-------+--------+ | 6 | hhh | ddd | +--------------+----------+-------+ then $result = mysqli_query($con,"SELECT b.id , b.title , b.copies FROM books b LEFT JOIN user_info u USING (title) GROUP BY b.id HAVING COUNT(u.title) < b.copies"); while($row = mysqli_fetch_array($result)) { echo ("<option value='$row[title]'>$row[title]</option>"); } generated HTML <select name="books"> <option value="">Select a Book</option> <option value="bbb">bbb</option> <option value="ddd">ddd</option> </select>
  25. I know. I usually use !feof() and was confusing myself.
×
×
  • 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.