Jump to content

Barand

Moderators
  • Posts

    24,603
  • Joined

  • Last visited

  • Days Won

    830

Everything posted by Barand

  1. It's the short term memory that goes fir ...... what was I saying?
  2. It's guaranteed with my code - the hour is the array key
  3. Even assembler - treated as an address (array name equivalent) and an offset (index equivalent) from that address
  4. Provided that you can spell "February", only two of those formats do not work $dates = [ 'feb 21, 1999', 'February 21, 1999', '02/21/99', '2/21/99', '99/2/21', '2-21-1999', '19990221', 'sun, Feb 21, 1999', 'Sunday February 21, 1999' ]; echo '<pre>'; foreach ($dates as $dstr) { printf("%-30s%-15s%s\n", $dstr, date('Y-m-d', strtotime($dstr)), strtotime($dstr)==0 ? 'X' : '' ); } Outputs feb 21, 1999 1999-02-21 February 21, 1999 1999-02-21 02/21/99 1999-02-21 2/21/99 1999-02-21 99/2/21 1970-01-01 X 2-21-1999 1970-01-01 X 19990221 1999-02-21 sun, Feb 21, 1999 1999-02-21 Sunday February 21, 1999 1999-02-21 For rogue formats you can always use DateTime::createFromFormat()
  5. Each time the status changes you need to store the status and timestamp in a new record. You may even want to store old_status|new_status|timestamp. In addition, each record will need the id of whatever the status refers to.
  6. But the only table reference by that query is "match_summ" (the one you are inserting into). As mentioned, what are you trying to do?
  7. What error message? Give us a clue.
  8. Have you tried it without the WHERE line? That will give all scores with ranks. Is $udid numeric? If not, it needs to be inside single quotes. (Really it shouldn't be in the query at all, it should be a prepared query with a placeholder for the udid parameter. But that's another lesson.
  9. You can do something like this my data mysql> select * from score; +-------+-------+ | name | score | +-------+-------+ | Bob | 75 | | David | 106 | | Jane | 75 | | Joe | 61 | | Mary | 59 | | Mike | 61 | | Sam | 76 | +-------+-------+ 7 rows in set (0.00 sec) query SELECT a.name , a.score , COUNT(b.name)+1 as rank , tot FROM score a JOIN (SELECT COUNT(name) as tot FROM score) as total LEFT JOIN score b ON b.score > a.score WHERE a.name = 'Jane' -- OPTIONAL GROUP BY a.name ORDER BY a.score DESC; +------+-------+------+-----+ | name | score | rank | tot | +------+-------+------+-----+ | Jane | 75 | 3 | 7 | +------+-------+------+-----+
  10. The only query you have posted will only return a single result with a count in it, so sorting one record does not make sense. What are you trying to achieve?
  11. You would have to assign log records to a specific goal. So you would store the id of a goal record in each log record. +-----------+ | user | +-----------+ | userid |--+ | name | | | etc | | +-----------+ | | | +----------+ | | goal | | +----------+ | | goalid |---+ +-------<| userid | | | weighloss| | | units | | | whenby | | | etc | | +----------+ | | | +-------------+ | | tracklog | | +-------------+ | | userid | +-------<| goalid | | calories | | etc | +-------------+
  12. Regarding CASE statements, yes you can use them in an insert. BUT whether the one you propose is feasible is impossible to say without knowing what you are trying to accomplish. Where do "home_id", "away_id" and "l_team_id" come from in that statement?
  13. So there could be old tracklog records for a user that were targetted against a previous goal. At present, the calories burned in these would also be included against the latest goal.
  14. You shouldn't be putting $userid in the query string. It looks as though the actual query being executed is SELECT COUNT(udid) AS `rank` FROM myTable WHERE score > ( SELECT score from myTable WHERE udid = myLongUdidStringHere Because "myLongUdidStringHere" isn't in quotes, sql treats it as a column name. Try function getUserRanks($udid, $conn) { $sql = "SELECT COUNT(udid) AS `rank` FROM myTable WHERE score > ( SELECT score from myTable WHERE udid = :udid )"; $stmt = $conn->prepare($sql); $stmt->execute( [ ':udid' => $udid ] ); $ranks = $stmt->fetchObject(); return $ranks->rank; }
  15. Here's a replacemnt progress_bar function function progress_bar($width, $height, $calories, $target) { $bar = "<svg width='$width' height='$height' view_box='0 0 $width $height'>\n <rect x='0' y='0' width='$width' height='$height' fill='#CCC' />\n"; // calc width of bar for calories already burned if ($target==0) { $target = 1; } if ($calories > 0) { $cal_width = $calories * $width / $target; $bar .= "<rect x='0' y='0' width='$cal_width' height='$height' stroke='#ccc' fill='#3C3' />\n"; } else { $bar .= "<text x='5' y='16' font-size='9pt'>No data for user</text>\n"; } $bar .= "</svg>\n"; return $bar; }
  16. I get that I get that if the userid in the session data has no data in the tables Looks like there are 3 goal records for the user. I assumed 1. If there are several, how are they to be processed?
  17. Could be there is no target "weightlost" in the user's goal record
  18. If you are doing wildcard searches, using LIKE, you are stuck with the long version I'm afraid. Alternative is FULLTEXT index search. (Moving to MySql forum)
  19. Prefix the table name with the database name $sql = "SELECT ID, FirstName, Last Name, Email, Mobile, PromoCode FROM database1.table1 WHERE (Email LIKE ?) OR (Mobile LIKE ?) OR (PromoCode LIKE ?) UNION SELECT ID, FirstName, Last Name, Email, Mobile, PromoCode FROM database2.table1 WHERE (Email LIKE ?) OR (Mobile LIKE ?) OR (PromoCode LIKE ?) "; Databases must be on the same server.
  20. I created some test data. Try this session_start(); $_SESSION['userid'] = 2; // your's is probably set already $con=mysqli_connect($host,$username,$password,$dbname); if (mysqli_connect_errno()) { die("Failed to connect to MySQL: " . mysqli_connect_error()); } $bar_length = 400; $bar_height = 20; $sql = "SELECT SUM(caloriesburned) as calories_burned , CASE g.weightunit WHEN 'lbs' THEN 3500 ELSE 7700 END * weightlost as target_calories FROM goal g INNER JOIN tracklog t USING (userid) WHERE userid = ?"; $stmt = $con->prepare($sql); $stmt->bind_param('i', $_SESSION['userid']); $stmt->execute(); $stmt->bind_result($calories, $target); $res = $stmt->fetch(); function progress_bar($width, $height, $calories, $target) { $bar = "<svg width='$width' height='$height' view_box='0 0 $width $height'>\n <rect x='0' y='0' width='$width' height='$height' fill='#CCC' />\n"; // calc width of bar for calories already burned $cal_width = $calories * $width / $target; $bar .= "<rect x='0' y='0' width='$cal_width' height='$height' stroke='#ccc' fill='#3C3' />\n"; $bar .= "</svg>\n"; return $bar; } ?> <!DOCTYPE html> <html> <head> <title>Sample Progress Bar</title> </head> <body> Calories burned to date : <?=$calories?><br> Target calories : <?=$target?><br> <?= progress_bar($bar_length, $bar_height, $calories, $target) ?> </body> </html>
  21. The quotes should be around the 'userid' bit.
  22. Why have you added the quotes around $_SESSION['userid'] ?
  23. The definition of the progress_bar function EDIT: You need to turn on error reporting in your php.ini file
  24. Keep it simple $inside = []; while($row = $result->fetch_array()) { $hour = date('G', strtotime($row['time'])); $inside[$hour] = $row['temp']; }
×
×
  • 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.