Jump to content

Barand

Moderators
  • Content Count

    19,099
  • Joined

  • Last visited

  • Days Won

    361

Everything posted by Barand

  1. Barand

    MySQL pulling results twice

    Youe should be storing the category_id (and not the category name) in the menu_item table. That would also save you from having to do this CASE c.menu_item_category WHEN 'Starter' THEN 1 WHEN 'Main' THEN 2 WHEN 'Dessert' THEN 3
  2. Barand

    MySQL pulling results twice

    In your sample output above every row is different, so what do you mean by "results being populated twice"?
  3. Barand

    Site Won't Submit Multiple Variables

    Hint: SELECT ... WHERE id IN (1, 2, 3) which is equivalent to SELECT ... WHERE (id = 1) OR (id = 2) OR (id = 3)
  4. Barand

    SELECT QUERY from table with no relationship

    Create a table subquery to calculate the total points for each user and join that to the rewards table using the points total. (In my example I assume you have a table called points. SELECT first_name , last_name , total_points , reward FROM { SELECT first_name , last_name , SUM(points) as total_points FROM user u JOIN points p ON u.userID = p.userID GROUP BY u.userID } tot LEFT JOIN rewards r ON tot.total_points = r.valuePoints
  5. Barand

    SELECT QUERY from table with no relationship

    Why? The principle behind relational databases is that attributes, like names, are stored in only one place. There is no good reason for duplicating them in another table. Or are you talking about output html tables - it isn't clear. The values in your example data do not match the description of what you are attempting to do (unless you think 30 and 6663 are a match) making full understanding difficult.
  6. Barand

    Football League Table - Last 5 matches

    Knowledge of the relevant table structure greatly assists when trying to write queries.
  7. Barand

    array in mysql database?

    One of those statements can't be true. (JSON functions require MySQL 5.7+)
  8. Barand

    array in mysql database?

    Here's an example mysql> SELECT name, role FROM json_test; +-------+--------------+ | name | role | +-------+--------------+ | Peter | [1, 2, 3] | | Paul | [1, 3] | | Mary | [1, 2, 4] | | Jane | [2, 4] | | Fred | [1, 2, 3, 4] | +-------+--------------+ 5 rows in set (0.00 sec) mysql> SELECT name, role FROM json_test WHERE JSON_CONTAINS(role, "3"); +-------+--------------+ | name | role | +-------+--------------+ | Peter | [1, 2, 3] | | Paul | [1, 3] | | Fred | [1, 2, 3, 4] | +-------+--------------+ 3 rows in set (0.00 sec)
  9. Barand

    Selecting Similar Records from the Same Table

    Just to give a bit of processing help. To build the array foreach row in the results $data[name][mname] = paid endforeach to output to html table output table headings row foreach data as name = namedata start new output row output name cell foreach namedata as paid output paid cell endforeach end output row endforeach
  10. Barand

    Selecting Similar Records from the Same Table

    The query would become SELECT name , date_format(mont, '%b') as mname , paid FROM feerecord WHERE QUARTER(mont) = 1 AND YEAR(mont) = 2019 ORDER BY name, mont The array structure remains unaltered
  11. Barand

    upgrade OR implimentation problem

    If you won't answer my question, why should anyone answer yours?
  12. Barand

    upgrade OR implimentation problem

    Now it's even more confusing. What does your data look like? - it's hard to build a picture from what you've given us.
  13. Barand

    upgrade OR implimentation problem

    What is your code for querying your data and producing the values you want to output?
  14. Barand

    Selecting Similar Records from the Same Table

    I'd use a query like this SELECT name , month , paid FROM feerecord ORDER BY name, month and as I read each record, build an array like this $data = [ 'name1' = [ 'Jan' => 'Y', 'Feb' => 'Y', 'Mar' => 'N' ], 'name2' = [ 'Jan' => 'N', 'Feb' => 'Y', 'Mar' => 'N' ], ]; You can then loop through the array to get your desired output. Note, you have made life difficult for yourself by using a non-sortable date format
  15. Barand

    help with a registration form

    If you define $sql BEFORE you try to execute it with mysqli_query() then you might get a better result
  16. Barand

    help with a registration form

    You use password_verify() to verify passwords.
  17. Barand

    Sessions Without Cookies in PHP 7

    Pretty much like estimating how long it will take to write a program The first 80% takes 80% of the time. The last 20% takes another 80% of the time.
  18. Barand

    MySQL Aggregate Query with multiple Conditions

    For future reference, I would have helped but I had a problem loading that picture of your data into a test table. Normally I would load posted data into a test table to work on a problem but queries wouldn't work with all the data in a blob field.
  19. Barand

    Duck!

    Do we score any points in today's "duck shoot"?
  20. Barand

    Important "if" statement relying on mySQL

    Why set a superflous boolean variable when you have a perfectly good boolean expression already. All you are doing is adding an extra step $too_many_labels will have the same value as $numberoflabels > 4 I'd go for option 1 or option 3, which would be // style 3 $labelCounter = $db->prepare("SELECT count(*) ... "); // mySQL counts labels if($numberoflabels > 4) { echo "Sorry visitor, no label could be created"; } else { // RUN BIG CURL SCRIPT IF LESS THAN 5 LABELS // LONG CURL SCRIPT GOES HERE $log = $db->prepare("INSERT into label_counter... // log the good label }
  21. Barand

    PHP7, MySQL8, Apache2.4

    Switch to PDO. It's much better than mysqli.
  22. Barand

    PHP7, MySQL8, Apache2.4

    Have you tried restarting the server since you made the ini changes?
  23. Barand

    PHP7, MySQL8, Apache2.4

    Check in your extensions folder to see what the names should be EG
  24. Barand

    Duck!

    The next "Fortnite" perhaps? 😄
  25. Barand

    PHP7, MySQL8, Apache2.4

    Extension names begin with php_ (windows) extension=php_mysqli.dll (linux) extension=php_mysqli.so
×

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.