Jump to content

Jim R

Members
  • Posts

    988
  • Joined

  • Last visited

  • Days Won

    1

Everything posted by Jim R

  1. I tried mostRecent.grade and mostRecent.nameLast in the inner select and outer select. I tried them in both at the same time. All three instances I got the following error: Unknown column 'mostRecent.grade' in 'field list' $query = "SELECT *,mostRecent.grade, mostRecent.nameLast FROM (SELECT p.id as pid, b.playerID as bplayerID, b.userID as buserID, s.toggle AS stoggle, o.toggle AS otoggle, p.city as pcity, p.school as pschool, s.city as scity, s.school as sschool, r.id as rid, r.opp_city as roppcity, r.opp_school as roppschool, o.city as ocity, o.school as oschool, r.city as rcity, r.school as rschool, r.nameFirst as rfirst, r.nameLast as rlast, p.nameFirst as pfirst, p.nameLast as plast FROM a_players_reviews r LEFT JOIN a_players p ON CONCAT (r.nameFirst,r.nameLast) = CONCAT (p.nameFirst,p.nameLast) LEFT JOIN a_schools s ON CONCAT(r.city,r.school) = CONCAT(s.city,s.school) LEFT JOIN a_schools o ON CONCAT(r.opp_city,r.opp_school) = CONCAT(o.city,o.school) LEFT JOIN a_player_bookmark b ON p.id = b.playerID && '". $userID ."' = b.userID WHERE bookmark>0 ORDER BY r.id desc LIMIT 15) mostRecent ORDER BY mostRecent.grade,mostRecent.nameLast ";
  2. I pasted your original query. It yielded the same set of errors we're getting now, and the order by columns at the end were not in the original select list, certainly not with mostrecent.grade and mostrecent.nameLast. Giving it a try.
  3. At least we're working down the query. 🥴
  4. Now I'm getting... Duplicate column name 'id' $query = "SELECT * FROM (SELECT *,p.id as pid, b.playerID as bplayerID, b.userID as buserID, s.toggle AS stoggle, o.toggle AS otoggle, p.city as pcity, p.school as pschool, s.city as scity, s.school as sschool, r.id as rid, r.opp_city as roppcity, r.opp_school as roppschool, o.city as ocity, o.school as oschool, r.city as rcity, r.school as rschool, r.nameFirst as rfirst, r.nameLast as rlast, p.nameFirst as pfirst, p.nameLast as plast FROM a_players_reviews r LEFT JOIN a_players p ON CONCAT (r.nameFirst,r.nameLast) = CONCAT (p.nameFirst,p.nameLast) LEFT JOIN a_schools s ON CONCAT(r.city,r.school) = CONCAT(s.city,s.school) LEFT JOIN a_schools o ON CONCAT(r.opp_city,r.opp_school) = CONCAT(o.city,o.school) LEFT JOIN a_player_bookmark b ON p.id = b.playerID && '". $userID ."' = b.userID WHERE bookmark>0 ORDER BY r.id desc LIMIT 15) mostRecent ORDER BY mostRecent.grade,mostRecent.nameLast ";
  5. Getting this error: Unknown column 'rfirst' in 'on clause' $query = "SELECT * FROM (SELECT *,p.id as pid, b.playerID as bplayerID, b.userID as buserID, s.toggle AS stoggle, o.toggle AS otoggle, p.city as pcity, p.school as pschool, s.city as scity, s.school as sschool, r.id as rid, r.opp_city as roppcity, r.opp_school as roppschool, o.city as ocity, o.school as oschool, r.city as rcity, r.school as rschool, r.nameFirst as rfirst, r.nameLast as rlast, p.nameFirst as pfirst, p.nameLast as plast FROM a_players_reviews r LEFT JOIN a_players p ON CONCAT (rfirst,rlast) = CONCAT (pfirst,plast) LEFT JOIN a_schools s ON CONCAT(rcity,rschool) = CONCAT(scity,sschool) LEFT JOIN a_schools o ON CONCAT(roppcity,roppschool) = CONCAT(ocity,oschool) LEFT JOIN a_player_bookmark b ON pid = bplayerID && '". $userID ."' = buserID WHERE bookmark>0 ORDER BY rid desc LIMIT 15) mostRecent ORDER BY mostRecent.grade,mostRecent.nameLast ";
  6. But that gets me back to the duplicate column error. I only messed around with the aliases because of that. So what you modified sent the duplicate column error.
  7. I've been searching for other samples on the Googles and play around with pid / p.id, I removed it from the SELECT, and the error moved to the next p. instance, 'p.city', saying it was a duplicate column name. Removed all the p. columns, and it turned to having a duplicate city column. I removed all the column names in the sub select, leaving just * , and I was back to having duplicate column 'id'. Is it not seeing any of the aliases?
  8. I set up the p.id as pid, r.id as rid and b.id as bid and now it says:
  9. Disregard. I had an omission, but now I'm getting this error:
  10. I'm getting a syntax error:
  11. Just the most recent 15 rows--so a_players_reviews 'r.id'. I have a timestamp as well, but r.id is the same. From there, I want to organize them by grade then last name. I did try r.id first in the Order By, but unless I'm missing something, that's not going to allow me to organize them the way I want to. I tried Group By r.id as well with Order By p.grade,p.nameLast, but same result (which makes sense).
  12. Any thoughts on how to get the results?
  13. Not sure what you were referring to.
  14. It is. Scroll across. (Either you didn't see it, or you're commenting on a typo in my explanation.) EDIT: Added a carriage return for visual assistance.
  15. I want to get the most recent 15 instances of my a_players_review table THEN sort them by grade, then last name. Ordering the r.id first just gives me a list of rows that I can't do much else with, unless I'm missing how I can code the output. Below is what I had. ORDER BY looked good until I started filling in more rows and seeing kids in grade = 2021 pushing more recent rows off the list. Nested ORDER BY seems frowned upon, and I'm not even sure they work. I kept getting parameters errors. I really can't make heads or tails of nested SELECTs. That might be the answer, but I've been unable to take what I've seen and apply it without getting a parameters error. $query = "SELECT *,p.id,b.playerID,b.id,s.toggle AS stoggle,o.toggle AS otoggle,p.city,p.school,s.city,s.school,r.opp_city,r.opp_school,o.city,o.school,r.city,r.school FROM a_players_reviews r LEFT JOIN a_players p ON CONCAT (r.nameFirst,r.nameLast) = CONCAT (p.nameFirst,p.nameLast) LEFT JOIN a_schools s ON CONCAT(r.city,r.school) = CONCAT(s.city,s.school) LEFT JOIN a_schools o ON CONCAT(r.opp_city,r.opp_school) = CONCAT(o.city,o.school) LEFT JOIN a_player_bookmark b ON p.id = b.playerID && '". $userID ."' = b.userID WHERE p.id = b.playerID && '". $userID ."' = b.userID && bookmark>0 ORDER BY p.grade,p.nameLast,r.id desc LIMIT 15 ";
  16. Yeah, I forgot it does that because when I use Textastic for code, it has separate keys for quotes and double quotes. I'll likely be the only one using an iPad to input data in my group, so that should be easy enough going forward.
  17. Turns out part of the problem using an iPad to enter that specific data to the table. Not sure why there is a difference in using ' and " on an iPad vs. a Mac, but there is. So I changed out all the single and double quotes (very early in this process, so it's not too big of an issue at the moment), then added this line... $update = mysqli_real_escape_string($con,$row['review']); Then stripslash($update) when I needed output.
  18. The addslashes didn't escape the single quotation marks in text (the subject of the topic). The exact code is echo str_replace("'","\'",$update);
  19. What am I replacing though? I searched a good amount on this topic, as addslash wasn't working. Adding \ to the text then stripping it looks to be a work around. I just thought there was a better way without forcing those doing the inputting to the table to add them. It's not very native. str_replace("'","'",$update) - didn't work. Neither did... str_replace("'","\'",$update)
  20. I have a paragraph in a text in my data table column with apostrophes and heights, like, "He'll likely grow beyond 6'6"." I've tried addslashes($update), but it's not working. (At another time I thought I had something like that.) Is there something that will take care of it short of typing \ before every instance I use quotes, the using stripslash?
  21. Never mind. I'm pretty sure @kicken output worked. I might've gotten my wires crossed. Thank you to both of you for your time.
  22. Upon further review, it's reversing the results, and reversing the +/- logic changes the rows that haven't had any action on them yet.
  23. Left joining as you had it didn't change anything, unless there was something in the output I needed to change. My query had a left join too.
  24. That's pretty damn close. For some reason it's not recognizing the last row of the data table, or let's say I have a + where there should be a -. I'm going to play around with what @Barand suggested too. I have a LEFT JOIN, but it's bookmark Left Join players instead of what Barand has.
  25. I have 64 rows of players and want each User to be able to choose to bookmark an player, as well as unbookmark it too. I have a bookmark table set up, and each time a User decides to bookmark(+) or unbookmark(-) an player a row is created in the data table. (Matching the player ID and User ID) That's working fine. A query reads the most recent row for each player to determine if there is a + or - button next to each player. Testing the query and adding some dummy data, that part of it works too. However, the issue is the initial state, which I want to be a +. Once I go live, the table will be empty, nothing for the query to return/produce. How do I create an initial state of a + with no rows and have it not used or swapped out when Users start clicking + or -? $query = "SELECT b.id, bookmark,playerID,userID,p.id FROM a_player_bookmark b LEFT JOIN a_players p ON '". $id ."' = playerID WHERE userID = '". $userID ."'&&'". $id ."' = playerID ORDER BY b.id desc LIMIT 1 "; $results = mysqli_query($con,$query); echo mysqli_error($con); while($row = mysqli_fetch_assoc($results)) { echo $row['bookmark']; if($row['bookmark'] == 0) { echo '-'; // this is where a form goes to remove a bookmark } else { echo '+'; // this is where a form goes to add a bookmark } } I tried to get it with CASE, but I don't think that's the right path. I also looked at UNION. I was able to get it to produce an initial state of +, but it still printed the already made up sample data too (so I have three instances of ++ or +-). (Players 2, 4 and 4) Here is the what the UNION query looked like: $query = "(SELECT b.id, bookmark,playerID,userID,p.id FROM a_player_bookmark b LEFT JOIN a_players p ON '". $id ."' = playerID WHERE userID = '". $userID ."'&&'". $id ."' = playerID ORDER BY b.id desc LIMIT 1) UNION (SELECT b.id, bookmark,playerID,userID,p.id FROM a_player_bookmark b LEFT JOIN a_players p ON '". $id ."' = playerID WHERE userID = '". $userID ."' ORDER BY p.id desc LIMIT 1) ";
×
×
  • 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.