Jump to content

dtyson2000

Members
  • Posts

    93
  • Joined

  • Last visited

Everything posted by dtyson2000

  1. Wanted to drop in and thank you again for suggesting that there is a MySQL solution. I've taken care of the entire thing that way. So it's all set. Thanks, again!
  2. It is indeed a date field in the database. Perhaps that is a better tach than trying to do it with PHP, although I'm sure there's a PHP solution as well. Thanks for the input!
  3. Hello. Can somebody have a look at this code? I would like it to return birthdays coming in the next three weeks. At the moment as it is, it does this only up to the end of December when it should also be pulling a birthday in the first week of January. I suspect it has something to do with the removal of the "Y"ear in the date formats but I'm not sure because when I add it back in, it returns nothing. The IF line is the suspected culprit. I'm not asking for someone to write code but simply confirm whether or not the issue falls where I suspect it does and maybe a quick explanation of what's wrong. I need to understand this. Thanks! // there is a column in the database called user_dob $user_birthday = date("m-d", strtotime($user_dob)); $curdate = date("m-d"); if ($curdate <= date($user_birthday, strtotime("+21 day"))) { code }
  4. If not NULLs, how can I achieve the end? I'm kind of lost now.
  5. Morning all! I have a query question (is that redundant?). I'm trying to retrieve the values from two tables that include common data but I'd also like to retrieve the uncommon data. The users table contains user data. The login table contains login data. Some users have logged in. Others have not. I'd like to calculate the number of days that it has been since each user has logged in, which I have achieved with the following query. However, I would also like to retrieve the names of users who have NOT yet logged in, thus those who have no data in the login table. It's probably something simple that I'm overlooking but I've hit the wall and wanted to throw it out there for your consumption. If someone could point me in a direction, that would be great! I hope I've described it decently enough. Here's what I have: users id | userid | name 1 | 123 | dave 2 | 456 | sue 3 | 789 | fido 4 | 112 | zippy login id | tuserid | logindate 1 | 123 | 2011-07-04 2 | 456 | 2011-05-30 3 | 789 | 2011-06-10 SELECT * FROM users, (SELECT DISTINCT tuserid, MAX(logindate), DATEDIFF(CURDATE(), MAX(logindate)) days_since_login FROM login GROUP BY tuserid) login_days WHERE (userid = tuserid || tuserid IS NULL) AND days_since_login > 10 I'd like to return: resulting table id | userid | days_since_login 1 | 456 | 41 2 | 789 | 30 3 | 112 | NULL Any thoughts?
  6. Sorry for the long-winded (and maybe convoluted) post. I actually figured it out. All I did was split up the query to grab data from the users and payment table based on the userid match. Then I threw a function outside the WHILE loop to query the checkin data based on the userid match from a posted variable. All works just fine. I love this stuff! Thanks for reading, anyway!
  7. Man I am loving this PHP/MySQL stuff but I'm running into a snag and I can't tell whether or not it's a conceptual thing that I can't see or if there's a simple solution surrounding the WHILE loop. I have three tables that all have a userid in common (users, payment, checkin). I'm joining them all to display data for each user (user data, payment data, how many times they've checked in and when). ---------------------------------------------------------------------------------- users (table 1) ---------------------------------------------------------------------------------- id | userid | username ----- | ----- | ----- 1 | 12345 | joe ---------------------------------------------------------------------------------- ---------------------------------------------------------------------------------- payment (table 2) ---------------------------------------------------------------------------------- id | payuid | janueary | february ----- | ----- | ----- | ----- 1 | 12345 | T | F --------------------------------------------------------------- ----------------------------------------------------------------------------------------- checkin (table 3) ----------------------------------------------------------------------------------------- id | chkuid | date | time ----- | ----- | ----- | ----- 1 | 12345 | 2011-02-01 | 16:45:00 ----- | ----- | ----- | ----- 2 | 12345 | 2011-02-02 | 14:45:00 ----- | ----- | ----- | ----- 3 | 12345 | 2011-02-02 | 17:45:00 ----- | ----- | ----- | ----- ----------------------------------------------------------------------------------------- My query has a couple of joins: SELECT * FROM users LEFT OUTER JOIN payment ON users.userid = payment.payuid LEFT OUTER JOIN checkin ON users.userid = checkin.chkuid WHERE (users.userid = '$userid') That $userid is posted from a form. What's happening is that the WHILE loop is looping through and finding everything I need but it's producing 3 sets of results (as there are three checkins in the third table), effectively repeating the html tables that I have displaying the user/payment data. Is there something I'm not thinking of conceptually with this query? Should it be separated somehow - like the checkin part in a separate function? Or can I somehow prohibit the repetition of data from the first two tables in the query while repeating the data for the third? Thanks so much for your time and expertise!
  8. Thanks, Fenway, for your input. I played around and played around with all sorts of parenthesis placement and came across an article that pointed me in a different direction. So far, it seems to work. Here's what I came up with: SELECT * FROM table1 LEFT OUTER JOIN table2 ON table1.userid = table2.t2userid WHERE (DATE(table2.date) != CURDATE()) && (DATE (!(table2.date) < CURDATE())) || table2.t2userid IS NULL How I got there... I'm still scratching my head. Thanks again!
  9. I need a fresh set of eyes here. I've screwed around with this query for too long trying to figure it out on my own. I'm just not as good as you people are. Thanks to the help of Kickstart, I've grown somewhat used to JOINS but this query is killing me. Here are the details: table1 id | userid | name --- | --- | --- 1 | 1234 | Joe --- | --- | --- 2 | 5678 | Amy --- | --- | --- 3 | 9012 | Paul --- | --- | --- 4 | 3456 | Michele table2 id | t2userid | date --- | --- | --- 1 | 5678 | 2011-05-29 --- | --- | --- 2 | 9012 | 2011-05-23 --- | --- | --- 3 | 5678 | 2011-05-23 --- | --- | --- 4 | 5678 | 2011-05-22 I have two tables, each with a common userid. User id's are taken from table 1 and entered into table 2 with the addition of a date. I would like to: 1) Query both tables (currently using a LEFT OUTER JOIN on table1.userid = table2.t2userid) 2) Return from table2 those userid's that DO NOT have today's date 3) Return ONLY ONCE from table2 those userid's that are less than today's date (unless they also have an entry with today's date - see number 1) 4) Return userid's that are not in table2 (currenly working table2.t2userid IS NULL) Current query (with a PHP variable supplying $today, supposing today is 2011-05-29): SELECT * FROM table1 LEFT OUTER JOIN table2 ON table1.userid = table2.t2userid WHERE table2.date != ".$today." AND !(table2.date < ".$today.") OR table2.t2userid IS NULL What I am getting: Joe --- Amy --- Amy --- Amy --- Paul --- Michele What I would like to get: Joe --- Michele Sorry if that seems convoluted. I'm just a little frustrated. Thanks for your earlier help and for taking the time to read! I hope to keep learning from you folks!
  10. Hello. I'm practicing working with two tables. I'd like to be able to select data from both and return only the rows that DO NOT have data in both. I'm just using today's date as the "kicker". If the userid appears in both tables and table 2 has today's date, those rows don't count. If there's no entry in table 2 with a userid and today's date from table 1, i'd like to return the info from table 1. table 1 ID | userid 1 | dave123 2 | sandy456 3 | joe789 table 2 ID | userid | date 1 | dave123 | 4/5/2011 2 | sandy456 | 4/5/2011 I'm incredibly stuck on how to return only "joe789". It's probably something totally elementary. Do I need to use some sort of JOIN? Thanks for all your support that I've read and learned from while lurking around!
×
×
  • 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.