-
Posts
24,606 -
Joined
-
Last visited
-
Days Won
831
Everything posted by Barand
-
using foreach to loop over resultset from fetch_assoc();
Barand replied to webdeveloper123's topic in PHP Coding Help
Where, in my pseudocode, is there a while loop and a do..while loop? -
using foreach to loop over resultset from fetch_assoc();
Barand replied to webdeveloper123's topic in PHP Coding Help
set total = 0 Read first row output customer details do { output item details add item value to total } while read next row output total -
using foreach to loop over resultset from fetch_assoc();
Barand replied to webdeveloper123's topic in PHP Coding Help
RTFM once in a while. https://www.php.net/manual/en/mysqli-result.fetch-assoc.php -
using foreach to loop over resultset from fetch_assoc();
Barand replied to webdeveloper123's topic in PHP Coding Help
@ginerjm It won't work! You're loop will now print only the last two ordered items - you've thrown the first one way. That is why there was a do..while() loop. Read first row output customer details do { output item details } while read next row -
using foreach to loop over resultset from fetch_assoc();
Barand replied to webdeveloper123's topic in PHP Coding Help
You fetch a row then print_r() it to see what it contains. Why are you surprised that it only shows the one row that you fetched? -
There appears to be a line missing from your code - the line where you take each row from your "$result1" and put them into "$item". For future reference, please post in English and tell us what the probem is and any error messages you might be getting.
-
Have you checked what is being sent and received by your AJAX calls? (Browser/Developr tools/Network tab)
- 3 replies
-
- php
- javascript
-
(and 1 more)
Tagged with:
-
Can't scrape/find 3 html tags in php simple html dom perser
Barand replied to shaadamin44's topic in PHP Coding Help
Maybe $xml = simplexml_load_string($html); $ul = $xml->xpath("//ul"); $tags = (array) $ul[0]->li; $tags= Array ( [0] => some text [1] => sometext [2] => sometext [3] => sometext )- 13 replies
-
Check the names of the input in your form. These POST fields don't exist $myName = addslashes( $_POST['name'] ); $myClass = addslashes( $_POST['class'] ); $myGender = $_POST['sex']; PS Find some recent tutorials - your HTML markup code is a decade or two out of date and deprecated. Use prepared statements instead of embedding user-provided data in your SQL.
-
generating invoice and getting values of quantity into an array
Barand replied to webdeveloper123's topic in PHP Coding Help
At least you now know why you can't. -
generating invoice and getting values of quantity into an array
Barand replied to webdeveloper123's topic in PHP Coding Help
Not quite the same https://www.php.net/manual/en/control-structures.while.php https://www.php.net/manual/en/control-structures.do.while.php -
generating invoice and getting values of quantity into an array
Barand replied to webdeveloper123's topic in PHP Coding Help
Why are you using both a while() loop and a do..while() loop? When the while loop finishes there a re no rows left to read. I showed you how to do it. Apparently that was a total waste of my time. -
<form action="comment.php?post_id=<?php $_GET['post_id'];?>" method="post"> That code will generate a link with no id value, like this... <form action="comment.php?post_id=" method="post"> It needs to be either <form action="comment.php?post_id=<?php echo $_GET['post_id'];?>" method="post"> or <form action="comment.php?post_id=<?= $_GET['post_id'] ?>" method="post">
-
Am having problems updating this php script to work with php v8
Barand replied to wixil's topic in Third Party Scripts
@mac_gyver's first reply told you what was wrong with that line - yet there it is again, unchanged. If you ain't listening why are you posting? -
generating invoice and getting values of quantity into an array
Barand replied to webdeveloper123's topic in PHP Coding Help
Here's a mysqli version <?php include '../db_inc.php'; $link = myConnect('test'); $last_id = 1046; $invoice="SELECT order_details.order_id , DATE_FORMAT(orders.order_date, '%M %e %Y') as order_date , concat(customer.first_name, ' ', customer.last_name) as customername , customer.address , customer.town , customer.county , customer.post_code , product.name as productname , order_details.qty , order_details.qty * product.price as amount FROM order_details JOIN orders ON orders.order_id = order_details.order_id JOIN customer on customer.customer_id = orders.customer_id JOIN product ON order_details.product_id = product.product_id WHERE order_details.order_id = $last_id"; $invoiceOutput = $link->query($invoice); $inv_total = 0; $row = $invoiceOutput->fetch_assoc(); // READ 1st ROW OF RESULTS // RETRIEVE AND OUTPUT THE INVOICE HEADER STUFF $output = "<table style = 'width: 400px;'><tr><td><b>Customer<b></td><td>{$row['customername']}</td></tr> <tr> <td> </td> <td> {$row['address']}<br> {$row['town']}<br> {$row['county']}<br> {$row['post_code']}<br> </td> </tr> <tr><td><b>Order No<b></td><td>" . sprintf('%06d', $last_id) . "</td></tr> <tr><td><b>Order Date<b></td><td>{$row['order_date']}</td></tr> </table><br><br> <table style='width: 500px; border-collapse: collapse;'> <tr style='background-color:#000; color: #FFF'> <td><b>Product</b></td> <td><b>Quantity</b></td> <td style='text-align: right;'><b>Amount</b></td> </tr> "; do { // LOOP THROUGH RESULTS OUTPUTTING DETAIL LINES $output .= "<tr><td>{$row['productname']}</td> <td>{$row['qty']}</td> <td style='text-align: right;'>{$row['amount']}</td> </tr>"; $inv_total += $row['amount']; } while ($row = $invoiceOutput->fetch_assoc()); // OUTPUT THE TOTAL $output .= "<tr><td colspan='3'> </td></tr> <tr><td colspan='2'><b>TOTAL</b></td><td style='text-align: right;'>$inv_total</td></tr> </table> "; echo $output; ?> Giving -
I think that's the only time I've seen that behaviour. I usually look at the notifications but then go to the activity (condensed) list and go to the topic from there. That way I can see if they've been responded to already or not. On that occasion the notified topic wasn't there - normally they are there pretty much straight away. The heading at the top is "All Activity"
-
I've never changed any stream settings, so default. The forums I follow are PHP Coding SQL/Database Client Side
-
To keep the debate lively I'll throw in another option - store the answers in an html form's input fields. When they finish they can submit or start again. You could show the questions one at a time, using javascript to hide the one just answered and display the next.
-
I think they appeared about an hour later when there was another comment on same topic. An hour is long lag for what is essentially the same data, slightly different query
-
After writing my version I compared it to yours and noticed it was almost identical to your subquery. Your version only needed the query you have in the subquery (+ HAVING clause + ORDER BY). The rest was completely superfluous.
-
Activity (condensed mode) is losing topics). Today I had 2 notifications for a topic Which appear in the expanded activity page But have disappeared from the condensed version
-
generating invoice and getting values of quantity into an array
Barand replied to webdeveloper123's topic in PHP Coding Help
Yes, it's to preserve the price at which the product was sold so that historical reports can use that price and not the price it is currently being sold at (if at all). Keeps the accounting straight. -
Does this give what you need? SELECT roster_no , drill_date , count(distinct drill_no) as drills FROM mms_drills JOIN mms_drillatt USING (drill_no) WHERE YEAR(drill_date) = '2022' AND description Not Like '%National%' GROUP BY roster_no, drill_date HAVING drills > 1;
-
What are the keys on those table?
-
As in Test data : that data for which the query works