Jump to content

Barand

Moderators
  • Posts

    24,607
  • Joined

  • Last visited

  • Days Won

    831

Everything posted by Barand

  1. The quotes should be around the 'userid' bit.
  2. Why have you added the quotes around $_SESSION['userid'] ?
  3. The definition of the progress_bar function EDIT: You need to turn on error reporting in your php.ini file
  4. Keep it simple $inside = []; while($row = $result->fetch_array()) { $hour = date('G', strtotime($row['time'])); $inside[$hour] = $row['temp']; }
  5. My code assumed a PDO connection. I have changed it to mysqli using a prepared statement. $con=mysqli_connect("localhost","root","password","registration"); 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(); echo progress_bar($bar_length, $bar_height, $calories, $target);
  6. Something like this $userid = somevalue; // however you decide which user $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 = $pdo->prepare($sql); $stmt->execute( [$userid] ); $res = $stmt->fetch(); echo progress_bar($bar_length, $bar_height, $res['calories_burned'], $res['target_calories']);
  7. We would need to know the structure of your tables to answer that
  8. Given the target calories and calories to date, then this will give a simple progress bar $bar_length = 400; $bar_height = 20; $target = 1000; // target calories need to burned off $calories = 650; // calculated total burned off so far echo progress_bar($bar_length, $bar_height, $calories, $target); // output progress bar 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; }
  9. How are you calculating the calories needed to burned from the target weight loss?
  10. Your final ")" is in the wrong place. It needs to be in the position marked below echo $this->date->add($this->set_interval($del_tim_holder_1[count($del_tim_holder_1)] * 7))->format("d.m.Y"); ^
  11. try foreach (range('A','Z') as $alpha) { echo "<li data-text='$alpha'>$alpha</li>\n"; }
  12. $date = '16.02.2017'; $days = 21; // create dateTime object $dt = new DateTime($date); // create a dateInterval $di = new DateInterval("P{$days}D"); // add interval to the date echo $dt->add($di)->format('d.m.Y'); //--> 09.03.2017
  13. Do you have php error reporting switched on? You certainly aren't checking if there was a mysql error.
  14. Looks like the "space" is some other whitespace character. What does SELECT HEX(price) as hexprice; give you?
  15. That gives mysql> SELECT price -> , CAST(REPLACE(price,' ','') AS signed) as number -> FROM test -> ORDER BY CAST(REPLACE(price,' ','') AS signed); +--------+--------+ | price | number | +--------+--------+ | 8 082 | 8082 | | 8 791 | 8791 | | 8 791 | 8791 | | 9 374 | 9374 | | 9 823 | 9823 | | 10 186 | 10186 | | 12 257 | 12257 | | 12 698 | 12698 | | 13 959 | 13959 | | 14 463 | 14463 | | 14 920 | 14920 | | 15 132 | 15132 | | 16 023 | 16023 | | 16 117 | 16117 | | 16 606 | 16606 | +--------+--------+ So, except for "table" being a reserved word and not to be used as a table name, I see no problem. edit: But why are you storing prices as text? Why not just use DECIMAL.
  16. The query you posted returns nothing but a syntax error. There is a missing ")" after the first "signed"
  17. try $startStamp = 1487156507; $endStamp = 1487156573; $dt1 = new DateTime("@$startStamp"); $dt2 = new DateTime("@$endStamp"); echo $dt1->diff($dt2)->format('%H:%I:%S').'<br>'; //--> 00:01:06
  18. 'value'=>'Valor de referencia de 1 bitcoin incluindo taxas: R$ ' . number_format($ask * 1.025, 2);
  19. Then alter the solution, adapting it to your needs.
  20. Putting the first 20 sets of data into excel and plotting a polynomial trendline gave y = 2.3226x3 - 1.5788x2 - 22.829x + 43.886 So you could use that or approximate it to $y = 2.323 * pow($x, 3);
  21. That code that I linked you to was in a thread of yours from a few weeks ago, yet here you are again with the same problems Have another look at the linked code - particularly at how parameters are used in prepared queries.
  22. Looks like it may be a problem similar to this one
  23. Perhaps it is suffering from a surfeit of parentheses.
  24. Yes - it has been serialized twice. Serialize the array into a string Serialize the resulting string To unravel it, unserialize twice print_r( unserialize(unserialize('s:287:"a:8:{s:5:"price";a:2:{s:5:"value";s:5:"38000";s:8:"original";s:0:"";}s:17:"custom_tax_inside";s:0:"";s:15:"custom_tax_page";s:0:"";s:8:"city_mpg";a:1:{s:5:"value";s:0:"";}s:11:"highway_mpg";a:1:{s:5:"value";s:0:"";}s:12:"custom_badge";s:0:"";s:5:"video";s:0:"";s:10:"short_desc";s:0:"";}"'))); Gives Array ( [price] => Array ( [value] => 38000 [original] => ) [custom_tax_inside] => [custom_tax_page] => [city_mpg] => Array ( [value] => ) [highway_mpg] => Array ( [value] => ) [custom_badge] => [video] => [short_desc] => )
×
×
  • 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.