-
Posts
24,566 -
Joined
-
Last visited
-
Days Won
822
Everything posted by Barand
-
Explain "doesn't work". What symptoms are you experiencing that leads you to that conclusion? Give us a clue.
-
What exactly is your problem if you can get it to work?
-
mysqli_real_escape_string alternative for decimal ?
Barand replied to bambinou1980's topic in PHP Coding Help
For your order status another option is to use an ENUM type field CREATE TABLE IF NOT EXISTS `status_sample` ( `id` int(11) NOT NULL AUTO_INCREMENT, `name` varchar(40) DEFAULT NULL, `status` enum('Not Done','Produced') DEFAULT 'Not Done', PRIMARY KEY (`id`) ); INSERT INTO status_sample (name, status) VALUES ('Peter', 1), ('Paul', 2), ('Mary', 1); SELECT * FROM test.status_sample; +----+-------+----------+ | id | name | status | +----+-------+----------+ | 1 | Peter | Not Done | | 2 | Paul | Produced | | 3 | Mary | Not Done | +----+-------+----------+ -
need to add a the option to export data to a csv file
Barand replied to kat35601's topic in PHP Coding Help
Have your button link to another php file. That other php file should contain only code that queries the table and downloads the file. for example: mydownload.php <?php $mysqli = new mysqli(HOST,USERNAME,PASSWORD,'test'); $sql="SELECT uompschedulenumber, uompscheduleColor,jmaPartID,ompSalesOrderID, uomlSorP,serial,rail,panel,stile,upsdescription,itemtype,jmaPartShortDescription , uomlStyleGroup,status , Case when status=10 then 'Created' when status=3 then 'PreSanding' when status=4 then 'PrePaint' else '' end as Status1 FROM WIP_master where redtag='Y' and redtagclosed !='Y' and status=10 order by uompschedulenumber,uomlSorP,upsdescription,jmaPartID "; // call the download sql2csv($mysql, $sql, 'orderstatus.csv', 1); /***************************** download function ******************************/ function sql2csv($mysqli, $sql, $filename='', $headings=1) /** * Parameters * $mysqli - connection * $sql - the sql query to be executed * $filename - name of download file (default "download_yymmddhhii.csv") * $headings - 1 if fieldname headings required (default), 0 if not required */ { if (!$filename) $f = 'download_' . date('ymdhi') . '.csv'; else $f = $filename; $fp = fopen('php://output', 'w'); // so you can fputcsv to STDOUT if ($fp) { $res = $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); } } -
mysqli_real_escape_string alternative for decimal ?
Barand replied to bambinou1980's topic in PHP Coding Help
-
Searching mysql table for the multiple orders by the same person.
Barand replied to blmg2009's topic in PHP Coding Help
WHERE id IN (3,2,1) will give exactly the same results as WHERE id IN (1,2,3) -
mysqli_real_escape_string alternative for decimal ?
Barand replied to bambinou1980's topic in PHP Coding Help
All that customer info should be in the customer table, not repeated in every order record. Only the customer_id should be in there so you can join to the customer table. -
How can we answer that question when we have absolutely no idea what, if anything, you are putting the "myname" field? And what is in $url? How does it get there?
-
Should be <?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>Points</th><th>" . join('</th><th>', $names) . "</th></tr>\n"; $newArray = array_fill_keys($names,''); // create blank array $newArray=array_merge(array('points'=>''), $newArray); // add points to the start of array for each question /***************************************************** * then you process the table data * storing the answers for each name in the array. * indexed by categor, question, name ******************************************************/ $sql = "SELECT category, question, points, 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,$p,$n,$a) = $res->fetch_row()) { if (!isset($data[$c][$q])) { $data[$c][$q] = $newArray; } $data[$c][$q][$n] = $a; // store the answer by name $data[$c][$q]['points'] = $p; // store the points for the question } $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> You should not be repeating data like question text, category name and points in every answer record. You should normalize your data so this information is held only once in the correct table. Key values (ids) are the only things that should be repeated in different tables to link the data together. +------------------+ +--------------+ | category | | user | +------------------+ +--------------+ | category_id (PK) |----+ +---| user_id (PK) | | cat_name | | | | name | +------------------+ | | +--------------+ | | | +--------------+ | | | question | | | +--------------+ | | | q_id (PK) |----+ | | | questiontext | | | | | points | | | +----<| category_id | | | +--------------+ | | | +-------------+ | | | answer | | | +-------------+ | | | ans_id (PK) | | | | answertext | | | | user_id |>----+ +----<| q_id | +-------------+
-
You will find line 6 immediately before line 7, and by "closing )" i mean ) while($aGame = mysql_fetch_assoc($rQuery) ) ^ | this is missing
-
Missing a closing ) at the end of line 6
-
My method, using strpos, produces The preg_replace method takes twice as long and produces
-
No, you are using Points as a key when it should be part of the data belonging to a question.
-
Slight change required to the WHERE and the LEFT JOIN condition 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 AND m.meta_key='priority' WHERE u.term_taxonomy_id='$taxonomy' AND post_status='publish' ORDER BY meta_value DESC
-
Search following the id links for matching ids
-
like this? $str = '<div class="text"> <mofish id="testing" type="testing" title="true" /> </div>'; $replace = 'whatever'; $p1 = strpos($str, '<mofish'); $p2 = strpos($str, '/>', $p1); $str = substr_replace($str, $replace, $p1+8, $p2-($p1+9));
-
perhaps +---------------+ | family_tree | +---------------+ | family_id | | firstname | | surname | | gender | | spouse_id | | mother_id | | father_id | +---------------+
-
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;
-
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
-
you need while (list($c, $q, $n, $a) = sqlsrv_fetch_array($stmt2, SQLSRV_FETCH_NUMERIC)) {
-
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>
-
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
-
With list() you need a numerically indexed array, hence my use of fetch_row()
-
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>