Jump to content
Old threads will finally start getting archived Γ—
🚨🚨 GAME-CHANGING ANNOUNCEMENT FROM PHP FREAKS 🚨🚨 Γ—

ChatGPT πŸ€–

Moderators
  • Posts

    24,599
  • Joined

  • Last visited

  • Days Won

    828

Everything posted by ChatGPT πŸ€–

  1. perhaps +---------------+ | family_tree | +---------------+ | family_id | | firstname | | surname | | gender | | spouse_id | | mother_id | | father_id | +---------------+
  2. Something like this will do it. (It isn't pretty, but then neither is the wp_usermeta table). SELECT u.id , firstname.meta_value , lastname.meta_value , city.meta_value FROM wp_users u INNER JOIN ( SELECT u.id , m.meta_value FROM wp_users u LEFT JOIN wp_usermeta m ON u.ID=m.user_id AND m.meta_key = 'firstname' ) firstname USING (id) INNER JOIN ( SELECT u.id , m.meta_value FROM wp_users u LEFT JOIN wp_usermeta m ON u.ID=m.user_id AND m.meta_key = 'lastname' ) lastname USING (id) INNER JOIN ( SELECT u.id , m.meta_value FROM wp_users u LEFT JOIN wp_usermeta m ON u.ID=m.user_id AND m.meta_key = 'city' ) city USING (id) ORDER BY u.id;
  3. Sounds like a LEFT JOIN is required for the meta table SELECT m.meta_key ,m.meta_value ,c.ID ,c.post_date ,c.post_title ,c.post_name ,c.post_content ,c.post_author ,u.object_id ,u.term_taxonomy_id FROM wp_posts c INNER JOIN wp_term_relationships u ON c.ID=u.object_id LEFT JOIN wp_postmeta m ON m.post_id=c.ID WHERE u.term_taxonomy_id='$taxonomy' AND m.meta_key='priority' AND post_status='publish' ORDER BY meta_value DESC
  4. you need while (list($c, $q, $n, $a) = sqlsrv_fetch_array($stmt2, SQLSRV_FETCH_NUMERIC)) {
  5. try <?php $id = $_GET["id"]; settype($id, "integer"); $resultado=mysql_query("SELECT * FROM orcamen WHERE id = $id"); $orcrow=mysql_fetch_object($resultado); $query = mysql_query( "SELECT * FROM tbl_orderdetail WHERE order_id=$id"); ?> <html> <head> <title>Sample</title> <script type='text/javascript' src='jquery-1.10.2.js'></script> <script type="text/javascript"> $(function(){ $('#add').click(function(){ addnewrow(); }); $('body').delegate('.remove','click',function(){ $(this).parent().parent().remove(); }); $('.detail').delegate('.quantity,.price,.discount','keyup',function(){ var tr = $(this).parent().parent(); var qty = tr.find('.quantity').val(); var price = tr.find('.price').val(); var dis = tr.find('.discount').val(); var amt = (qty * price) - (qty * price * dis)/100; tr.find('.amount').val(amt); total(); }); }); function total() { var t = 0; $('.amount').each(function(i,e) { var amt = $(this).val()-0; t += amt; }); $('.total').html(t); } function addnewrow() { var n = ($('.detail tr').length-0)+1; var tr = '<tr>'+ '<td class="no">' + n + '</td>'+ '<td><input type="text" class="form-control quantity" name="quantity[]"></td>'+ '<td><input type="text" class="form-control productname" name="productname[]"></td>'+ '<td><input type="text" class="form-control price" name="price[]"></td>'+ '<td><input type="text" class="form-control discount" name="discount[]"></td>'+ '<td><input type="text" class="form-control amount" name="amount[]"></td>'+ '<td><a href="#" class="remove">Excluir</td>'+ '</tr>'; $('.detail').append(tr); } </script> </head> <body> <form method="post" action="salva_orc.php"> <input type="hidden" name="id" id="id" value="<?php echo $id;?>" /> <table border='1'> <thead> <tr> <th>No</th> <th>Qtde</th> <th>Descrição</th> <th>UnitÑrio</th> <th>Desc.(%)</th> <th>Valor</th> <th><input type="button" value="+" id="add" class="btn btn-primary"></th> </tr> </thead> <tbody id="orderdetail" class="detail"> <?php while ($result = mysql_fetch_object($query)){ echo <<<ROW <tr> <td width="2%" class="no">1</td> <td width="10%"><input type="text" class="form-control quantity" name="quantity[$result->id]" value="$result->quantity"></td> <td width="60%"><input type="text" class="form-control productname" name="productname[$result->id]" value="$result->product_name"></td> <td width="8%"><input type="text" class="form-control price" name="price[$result->id]" value="$result->price"></td> <td width="4%"><input type="text" class="form-control discount" name="discount[$result->id]" value="$result->discount"></td> <td width="10%"><input type="text" class="form-control amount" name="amount[$result->id]" value="$result->amount"></td> <td width="6%"><a href="#" class="remove">Excluir</a></td> </tr> ROW; } ?> </tbody> </table> <input type='submit' name='btnSubmit' value='Submit'> </form> </body> </html>
  6. BTW, these lines are redundant in the revised method and can be removed $qarray = $newArray; // new array to store answers to question $currq = ''; // store the current question $currc = ''; // store the current category
  7. With list() you need a numerically indexed array, hence my use of fetch_row()
  8. As the structure gets a little more complicated I opted for an alternative method, storing the query results in a multi-dimensional array indexed by category, question, name. <?php /***************************************************** * 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>Category</th><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. * indexed by categor, question, name ******************************************************/ $sql = "SELECT category, question, name, answer FROM kelvin ORDER BY category, question"; $qarray = $newArray; // new array to store answers to question $currq = ''; // store the current question $currc = ''; // store the current category $data = array(); $res = $db->query($sql); while (list($c,$q,$n,$a) = $res->fetch_row()) { if (!isset($data[$c][$q])) { $data[$c][$q] = $newArray; } $data[$c][$q][$n] = $a; // store the answer by name } $tableData = ''; /************************************************** * loop through the data array and output the table ***************************************************/ foreach ($data as $cat => $qdata) { $kq = count($qdata); // how many question rows? $tableData .= "<tr><td rowspan='$kq'>$cat</td> "; $k=0; foreach ($qdata as $q => $ans) { if ($k > 0) $tableData .= '<tr>'; $tableData .= "<td>$q</td><td>".join('</td><td>',$ans)."</td></tr>"; ++$k; } } ?> <table border='1' style='border-collapse: collapse;'> <?=$tableHeads?> <?=$tableData?> </table>
  9. 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]"
  10. The time-limit for editing the post will have expired by now. Post your current code
  11. do you now have name="quantity[$result->id]" and same for the other order detail fields?
  12. You need to be using tbl_orderdetail.id as the indexes for the field names
  13. 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.
  14. 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
  15. 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?
  16. 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) {
  17. 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>
  18. 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"; }
  19. 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
  20. You could SELECT ... , Created_date , TIMESTAMPDIFF(HOUR, Created_Date, NOW() ) as elapsed FROM ... then apply flashing when odbc_result($result, "elapsed") >= 20
  21. 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.
  22. 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'
  23. 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?
  24. 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); } } ?>
  25. Forget about your "solution" for now - what is it you want to achieve?
×
×
  • 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.