Jump to content

Barand

Moderators
  • Posts

    24,563
  • Joined

  • Last visited

  • Days Won

    822

Everything posted by Barand

  1. I find that a large gin 'n' tonic at the end of a hard day is better than any tablets
  2. have a look at the examples --> http://php.net/manual/en/mysqli-stmt.fetch.php
  3. That's the best way. You can use query() with variables but have to escape them with real_escape_string() to prevent injection attacks
  4. You don't even have to do that
  5. So he does - missed that. Only open the connection once at top of script and pass the connection to any functions that need it. It will be closed automatically at end of script. The only time you need to open mid-script is if you change to another server.
  6. Stmt objects use the fetch method. The result objects (as in your first query) use fetch_assoc.
  7. try $file = "counter.txt"; $count = (file_exists($file)) ? file_get_contents($file)+1 : 1; file_put_contents($file, $count);
  8. For the sake of thread completion, and anyone else interested, here is the Version 2 code which cleans up the maths in the slope of the bars and uses a background image (attached). <?php $x0 = 50; // start point on x axis $y0 = 25; // minimum bar height $ybase = 7; // ht of bars from bottom of image $numbars = 40; // number of bars $barwid = 3; // bar width $barspace = 6; // bar spacing $slope = 30; // bar slope degrees from vertical $minval = -50; // min chart value $maxval = 150; // max chart value $vround = floor(($maxval-$minval)/$numbars); // round x values to nearest vround $slopefactorX = sin(deg2rad($slope)); $slopefactorY = cos(deg2rad($slope)); if (isset($_GET['value'])) { $value = floor($_GET['value']/$vround) * $vround; if ($value < $minval) $value = $minval; if ($value > $maxval) $value = $maxval; } else $value = null; function x($value, $minval, $vround, $x0, $barwid, $barspace) { $n = ($value - $minval)/$vround; // nth bar position return $x0 + $n * ($barspace + $barwid); } function y($value, $minval, $vround, $y0, $iheight) { $n = ($value - $minval)/$vround; // nth bar position $y = $y0 + pow($n, 2.2) / 50; return $y; } function drawBar($im, $x, $y, $iheight, $slopefactorX, $slopefactorY, $barwid, $ybase, $col) { $offset = floor(($y) * $slopefactorX); $pts = array ( $x, $iheight-$ybase, $x + $offset, $iheight-$ybase-floor($y*$slopefactorY), $x + $offset + $barwid, $iheight-$ybase-floor($y*$slopefactorY), $x + $barwid, $iheight-$ybase ); imagefilledpolygon($im, $pts, 4, $col); } /****************** * create the image *******************/ $im = imagecreatefrompng('icewolf2.png'); $iwidth = imagesx($im); // image width $iheight = imagesy($im); // image height $barbgc = imagecolorallocatealpha($im, 0x75, 0x75, 0x75, 60); $barcol = imagecolorallocate($im, 0xB3, 0xFA, 0x1A); /***************** * bar backgrounds ******************/ for ($v=$minval; $v<=$maxval; $v+=$vround) { $x = x($v, $minval, $vround, $x0, $barwid, $barspace); $y = y($v, $minval, $vround, $y0, $iheight); drawBar($im, $x, $y, $iheight, $slopefactorX, $slopefactorY, $barwid, $ybase, $barbgc); } /***************** * value bars ******************/ if (!is_null($value)) { for ($v=$minval; $v<=$value; $v+=$vround) { $x = x($v, $minval, $vround, $x0, $barwid, $barspace); $y = y($v, $minval, $vround, $y0, $iheight); drawBar($im, $x, $y, $iheight, $slopefactorX, $slopefactorY, $barwid, $ybase, $barcol); } } /***************** * output image ******************/ header("content-type: image/png"); imagepng($im); imagedestroy($im); ?>
  9. With the code I posted the absence of a value should give all grey bars <img src="chart.php" /> I've done a Mk.2 version which produces the attached images but Icewolf appears uninterested
  10. try it without the nested join SELECT etternavn,fornavn,Student.brukernavn, COUNT(nr) AS AntallOppgaver FROM Student INNER JOIN Fagdeltager ON Student.brukernavn=Fagdeltager.brukernavn INNER JOIN Oppgave ON Fagdeltager.fagkode=Oppgave.fagkode WHERE Fagdeltager.fagkode='DAT1000' GROUP BY etternavn,fornavn;
  11. Use array_filter() to remove empty items then join/implode $row['add_1'] = '15 north st'; $row['add_2'] = ''; $row['city'] = 'Macon'; $row['state'] = 'GA'; echo join(', ', array_filter($row)); // --> 15 north st, Macon, GA edit: If the address elements are part of a larger array you can use array_slice() to extract them EG $row['name'] = 'Fred'; $row['add_1'] = '15 north st'; $row['add_2'] = ''; $row['city'] = 'Macon'; $row['state'] = 'GA'; $row['phone'] = '132 456 7890'; echo join(', ', array_filter(array_slice($row,1,4))); // --> 15 north st, Macon, GA
  12. Are you talking about a 'placeholder' <input type="text" name="keyword" id="sbi1" size="20" placeholder="Enter keywords" />
  13. If you only have the id, exclude the name condition from the delete query.
  14. The above WHERE syntax is wrong. It should be either WHERE id = ? OR name = ? or WHERE id = ? AND name = ? depending on the logic you want to apply
  15. With daylight savings param = true, offset and timezones are 1 : Europe/London 2 : Europe/Paris 3 : Europe/Helsinki 4 : Europe/Moscow With the dst parameter = false 1 : Europe/Paris 2 : Europe/Helsinki 3 : Europe/Moscow 4 : Asia/Dubai
  16. Or you you could try looking at the solution Ignace gave you when you posted this same question about 3 days ago http://forums.phpfreaks.com/topic/283274-simple-math-problem/?do=findComment&comment=1455423
  17. The command you are looking for would be an UPDATE query using MySQL's REPLACE() function. Don't forget to backup the table before running mass updates.
  18. Use the correct username/password combination. Is the username the same as the database name when you connect with Dreamweaver?
  19. Here's an approximation (using GD library) of what you are trying to do. In practice, have a background image and plot bars over the top <?php $iwidth = 500; // image width $iheight = 120; // image height $x0 = 50; // start point on x axis $xmax = 450; // max point on x axis $vround = 5; // round x values to nearest vround $y0 = 30; // minimum bar height $barwid = 5; // bar width $slope = 8; // bar slope degrees from vertical $slopefactorX = sin(deg2rad($slope)); $slopefactorY = cos(deg2rad($slope)); $minval = -50; // min chart value $maxval = 150; // max chart value if (isset($_GET['value'])) { $value = floor($_GET['value']/$vround) * $vround; if ($value < $minval) $value = $minval; if ($value > $maxval) $value = $maxval; } else $value = null; function x($value, $minval, $vround, $x0, $barwid) { $n = ($value - $minval)/$vround; // nth bar position return $x0 + $n * 2 * $barwid; } function y($value, $y0, $iheight) { if ($value < 0) $value = 0; $y = $y0 + pow($value, 2) / 500; return $iheight - $y; } function drawBar($im, $x, $y, $iheight, $slopefactorX, $slopefactorY, $barwid, $col) { $offset = floor($y * $slopefactorX); $pts = array ( $x, $iheight, $x + $offset, $y*$slopefactorY, $x + $offset + $barwid, $y*$slopefactorY, $x + $barwid, $iheight ); imagefilledpolygon($im, $pts, 4, $col); } /****************** * create the image *******************/ $im = imagecreatetruecolor($iwidth, $iheight); $bgc = imagecolorallocate($im, 0x33, 0x33, 0x33); imagefill($im, 0,0,$bgc); $barbgc = imagecolorallocatealpha($im, 0xE0, 0xE0, 0xE0, 60); $barcol = imagecolorallocate($im, 0x80, 0xFF, 0x80); imageantialias($im, true); /***************** * bar backgrounds ******************/ for ($v=$minval; $v<=$maxval; $v+=$vround) { $x = x($v, $minval, $vround, $x0, $barwid); $y = y($v, $y0, $iheight); drawBar($im, $x, $y, $iheight, $slopefactorX, $slopefactorY, $barwid, $barbgc); } /***************** * value bars ******************/ if (!is_null($value)) { for ($v=$minval; $v<=$value; $v+=$vround) { $x = x($v, $minval, $vround, $x0, $barwid); $y = y($v, $y0, $iheight); drawBar($im, $x, $y, $iheight, $slopefactorX, $slopefactorY, $barwid, $barcol); } } /***************** * output image ******************/ header("content-type: image/png"); imagepng($im); imagedestroy($im); ?> Place in required place with HTML img tag, passing chart value in src querystring (-5 in the example below) <img src="chart.php?value=-5" />
  20. instead of or die(mysql_error()); you should be using or die(mysqli_error($con)); Then you might see some
  21. The UPDATE syntax is UPDATE table SET col1 = val1, col2 = val2, ....
  22. Try this to debug: if (!$stmt->execute() ) die($mysqli->error);
  23. Don't put variables inside single quotes echo $turl; // --> http://example.com echo '$turl'; //--> $turl
  24. Your dropdown needs to part of an HTML form. See http://php.net/manual/en/tutorial.forms.php
  25. Have you tried checking the value of $mysqli->error after executing the query?
×
×
  • 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.