Jump to content

Barand

Moderators
  • Posts

    24,604
  • Joined

  • Last visited

  • Days Won

    830

Everything posted by Barand

  1. SELECT fruit , MIN(price) as price FROM ( SELECT fruit, price FROM fruit1 UNION ALL SELECT fruit, price FROM fruit2 ) x WHERE fruit = 'grape'; +-------+------------+ | fruit | price | +-------+------------+ | grape | 3.00 | +-------+------------+
  2. SELECT fruit , MIN(price) FROM ( SELECT fruit, price FROM fruit1 UNION ALL SELECT fruit, price FROM fruit2 ) both_tables GROUP BY fruit; +-------+------------+ | fruit | MIN(price) | +-------+------------+ | grape | 3.00 | | lemon | 4.00 | | melon | 1.00 | +-------+------------+
  3. The most efficient way would be a single table. Whay have you got two tables holding the same data structure?
  4. That's what I added, but processing it now gives $value as an array and not as an object as it was originally being processed. I get the feeling a chunk has just been copied out of the original value (as there is only a single customer) and then pasted here. I suggest that @Thomas_L writes a function to process $value->users and return whatever he wants in that column, thus... '</td><td> <a href="">' . getUserData($value->users) . "</a></td></tr>"; Example function getUserData($udata) { $res = ''; foreach ($udata as $u) { $res .= "Name : {$u['firstName']} {$u['lastName']} <br>"; } return $res; }
  5. json_last_error_msg() says there's a syntax error when decoding the above. I shall have to scrutinize it. (I think I have a can of liquid scrute somewhere)
  6. Using attempted = [5,6] with the code I posted, I get... <ul id="list"> <li class="pagination-link" id="1">1</li> <li class="pagination-link" id="2">2</li> <li class="pagination-link" id="3">3</li> <li class="pagination-link" id="4">4</li> <li class="pagination-link is-current" id="5">5</li> <li class="pagination-link is-current" id="6">6</li> </ul>
  7. If you just want the print-r() output (???) then '</td><td> <a href="">' . print_r($value->users, true) . "</a></td></tr>";
  8. Also it would help more if you post the the json string $token_results instead of the print_r() output (which isn't processable by us)
  9. If you have allQst = [1,2,3,4,5,6] attempted = [5,6] then the indexes of 5 and 6 are different in those two arrays so I used the items as the id values function func(item, index) { var li = $('<li class="pagination-link"></li>').html(item).attr('id', item); ul.append(li); } function func2(item, index) { $("#"+item).addClass("is-current"); }
  10. For the sake of having a solution to this thread, put each in its own form. form input /form form input /form ...
  11. Not shorter with only two links, but less repetition foreach(['F','N'] as $x) $link["be{$x}1LP"]="https://www.site.com";
  12. As you did not define a field terminator it looks like it may have defaulted to "tab" separators. I prefer to use a php script to produce csvs and download them. MySql usually doesn't play nice when writing to files on the server. TEST FILE mysql> select * from client; +-----------+-------+----------+----------+---------------+----------+-------------+---------------+ | client_id | title | fname | lname | address | postcode | phone | email | +-----------+-------+----------+----------+---------------+----------+-------------+---------------+ | 3 | Mr | James | Bond | Thames House | W1 2QQ | 01232343456 | [email protected] | | 4 | Mrs | Margaret | Thatcher | Gotham City | GM1 3GG | NULL | | | 5 | Mr | Scott | Chegg | Coronation St | NULL | 16162554567 | | +-----------+-------+----------+----------+---------------+----------+-------------+---------------+ DOWNLOADED OUTPUT "client.csv" client_id,title,fname,lname,address,postcode,phone,email 3,Mr,James,Bond,"Thames House","W1 2QQ",01232343456,[email protected] 4,Mrs,Margaret,Thatcher,"Gotham City","GM1 3GG",, 5,Mr,Scott,Chegg,"Coronation St",,16162554567, CODE // // sample usage // $con = new mysqli(HOST,USERNAME,PASSWORD,'tutorial2'); $sql_query = "SELECT * FROM client"; sql2csv ($con, $sql_query, 'client.csv', 1); //***************************************************************************** // CSV download function //***************************************************************************** function sql2csv($con, $sql, $filename='', $headings=1) /** * Parameters * $con - 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 = $con->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); } }
  13. What symbol?
  14. Are you going to share the fix with others who may be reading this because they have a similar error?
  15. That is calling the execute() a second time. If username or email must be unique that could be generating a duplicate key error - check mysql error, don't just assume it's a connection error. Better still, put this line directly before your mysqli_connect() line mysqli_report(MYSQLI_REPORT_ERROR|MYSQLI_REPORT_STRICT); the all errors will throw a notification without all those if()s
  16. Not with your standard of formatting and indenting. It's impossible to spot where one ends and the next one starts and which are nested inside others.
  17. Your company hires a firm of expensive marketing consultants who dictate that the main colours in you site's pages should now be pink and lime green. Would you rather alter one css file for the whole site? alter every page in the site individually? resign
  18. Within your subject/grade loop you have two sections if($aliran=='S'){ $sql4="SELECT * FROM `qualification_result` where st_aliran='S'"; then else if($aliran=='A'){ $sql4="SELECT * FROM `qualification_result` where st_aliran='S'"; Should they both have where st_aliran='S' or should the second be where st_aliran='A' ?
  19. Repeat the total calculation for each array.
  20. That doesn't resemble any array I've seen before. If you do echo '<pre>' . print_r( $array , true) . '</pre>'; (where $array is the name of the array you are trying to process - $sub, $s, $y or whatever it is next time you post) then post the output, I can see what you are processing.
  21. BTW, have done an rsort(), array_pop() will get you the lowest value.
  22. Quicker to use array_slice() $y = [ 0, 4, 10, 8, 8, 10, 0, 14 ]; rsort($y); // descending sort /* check contents $y = Array ( [0] => 14 [1] => 10 [2] => 10 [3] => 8 [4] => 8 [5] => 4 [6] => 0 [7] => 0 ) } */ $top3total = array_sum(array_slice($y, 0, 3)); // get total of first 3 echo $top3total; // 34
  23. Interesting. Not only does the code need a rewrite (as I mentioned before) but I can now see the whole database needs rebuilding. Database tables should be normalized, (Google it) not populated with comma-separated lists. If you design the database correctly (so it supports the application), the coding gets a whole lot simpler, removing the need for those dozens of "if" conditions. (there is a tutorial link in my signature, which just happens to be based on students and results, that should give you a guide) [edit...] PS the DB should also eliminate duplicated and conflicting conditions...
  24. only this time your array is "$s" and not "$sub".
×
×
  • 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.