Jump to content

Barand

Moderators
  • Posts

    24,566
  • Joined

  • Last visited

  • Days Won

    822

Everything posted by Barand

  1. What you will need is an AI sort function (v7.7 ?) which intuitively knows how you want to process each schoolname in the data, If you don't have that you have same sort problems in PHP as you do with SQL.
  2. but not always, apparently ... Sounds like you schools have a "formal name" and a "nickname", like users might have.
  3. Then store the school name as it is named and don't mess around with removing/not removing city names. Use | City | School ----+----------------+---------------------- 0 | NULL | Kokomo 0 | NULL | Logansport 0 | NULL | Marion 1 | Lafayette | Lafayette Jefferson 0 | Lafayette | McCutcheon 0 | West Lafayette | Harrison If you sort the above by school only you get the order you wanted
  4. Extremely inefficient. Connecting to the db server probably takes longer than the query so that's quite an overhead you are adding to your script. You should connect once to the server at the start of the script and pass the connection as a parameter to any functions that need it. The connection will close automatically when the script finishes its execution.
  5. What does the data say?
  6. In my previous post I outlined the dangers of having duplicate column names in your tables and to use aliases to differentiate when this occurs. But it appears that you couldn't be bothered to read it because you immediately came up with this query with three sets of duplicates... select distinct gp.gp_id as gp1 ,gp.pid ,gp.author_gp ,gp.gname ,gp.type --+ ,gp.title --+ | ,gp.data | --+ | ,gp.pdate | | | ,gp.group_id | | | ,gp.author_id | | | ,u.avatar | | | ,u.user_id | | | ,up.update_id as up1 | | | ,up.update_body | | | ,up.time | | | ,up.title --+ | | ,up.account_name | | ,up.author | | ,up.type | --+ ,up.data --+ from group_posts as gp join user as u on u.uname=gp.author_gp join updates as up on u.uname=up.author where gp.gname='MEP news' and up.update_id >391 and up.author in("shan2batman", "aboutthecreator") order by time,pdate desc limit 0,5 Stop wasting our time.
  7. Do not use "SELECT * ", specify the columns you need. This is especially true when joining tables and those tables have columns with the same names. In this case you should use column aliases if you need both. EG SELECT g.type as gtype u.type as utype FROM ... The default fetch mode is PDO::FETCH_BOTH so your output with contain each column value with both a column name and a column number as array keys Examining you example output, this is the case for the first few columns ... Array ( [gp_id] => 103 [0] => 103 [pid] => 0 [1] => 0 [gname] => MEP news [2] => MEP news [author_gp] => aboutthecreator [3] => aboutthecreator but then you have ... [type] => a [4] => 0 [title] => qwertyu [5] => 2 and the relationship has broken down because a column "type" from a second table has overwritten the value for column "type" in the first table" Checking the later columns in your example output finds numeric keys without corresponding name keys (the duplicated names that were overwritten) .. [19] => 0 [20] => 0 [21] => qwertyu Depending on how you process these results you will get different outcomes. When you open your PDO connection, specify a default fetch mode EG $db->setAttribute(PDO::ATTR_DEFAULT_FETCH_MODE, PDO::FETCH_ASSOC); then, on occasions when you specifically need the numeric keys, do ... $row = $stmt->fetch(PDO::FETCH_NUM);
  8. I notice the above line in your function - is that creating a connecting to your database? appearing in every function?
  9. Why **ss about when there are inbuilt functions that can accomplish the task far more efficiently? function reformatTime($tstr) { $dt = DateTime::createFromFormat('h:i:sa', $tstr); return $dt->format('H:i:s'); } echo reformatTime('08:30:00PM'); //--> 20:30:00
  10. You check that it isn't empty before running the query. At present, if $_GET is not set, you run the query to fetch all data. Get out of the habit of using "SELECT * ", specify the columns you need to retrieve.
  11. For example, https://www.php.net/manual/en/datetime.createfromformat.php https://www.php.net/manual/en/datetime.format.php
  12. The "Activity" page no longer has a "condensed" option. Selecting condensed has no effect and on refresh it reverts to "Expanded" mode. (This worked fine "last year" and the problem seems has appeared overnight)
  13. Merely defining a query string does not execute the query. If $name is empty you have "LIKE '%%' " which will match every record in the table
  14. Just before the" new mysqli()" line in that case. That's the statement that is connecting to your db server.
  15. Always put this line of code mysqli_report(MYSQLI_REPORT_ERROR|MYSQLI_REPORT_STRICT); before the line in your code that calls mysqli_connect()
  16. I guess the designers of the forum software thought emojis were far more important
  17. I have no such problems with my phone
  18. What if you rotate to landscape?
  19. It does disappear with narrow display sizes. Try shrinking your display (zoom out/ Ctrl-minus)
  20. Are you checking if data has actually been POSTed if ($_SERVER['REQUEST_METHOD'] == 'POST') { $nine = $_POST['username2']; $codx = $characters[$nine]->name; } else { echo "NO DATA!"; }
  21. It's [ code ]…[ /code ] (but without the spaces) or just use the <> button on the toolbar
  22. I appreciate that you need to reformat the date, but why to one with a different day, different month and 18,000 years later? However, one way to do it is to treat your date as a string value initially (ie column type VARCHAR) while you do the import. Once imported, run an update query to reformat to correct date format UPDATE mytable SET datum = TO_TIMESTAMP(datum, 'DD.MM.YYYY'); Once you have the correct format you can alter the column from VARCHAR to DATE type
  23. I cannot understand why you would change to
  24. The fastest way, by far, is to export from Access into a CSV file then use a LOAD DATA INFILE command in SQL to load the csv into the database table. The next fastest way is to take advantage of MySQL's multiple insert queries EG INSERT INTO mytablename (col1, col2, col3) VALUES (1, 'aaa', 'bbbb'), (2, 'bbb', 'cccc'), (3, 'ccc', 'dddd'), . . . (998, 'ddd', 'eeee'), (999, 'eee', 'ffff'); and load several hundred records with each insert. The slowest way is to iterate through a file, inserting one record at a time.
×
×
  • 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.