Jump to content

Barand

Moderators
  • Posts

    24,566
  • Joined

  • Last visited

  • Days Won

    822

Everything posted by Barand

  1. Does this version give you the same problem? If so, post your revised data. benanamen_1.php benanamen_2.php date_opt_funcs.php
  2. You may have only 3 but joining to a table with >1 matching records can increase that. You check slab date is within the date range but what about dried_in and complete dates?
  3. SELECT @wk:=0 as init0 , @day1 := '2015-10-11' as init1 , @day2 := '2016-01-09' as init6 . . .
  4. First thing you need is a form for the user to select the start and end dates. This is where you would preset the start and end with the defaults of 3 months ago and now. I would recommend using date pickers, or date select dropdown menus, so you have control over the format of the dates that are submitted. As you are charting in weeks you would also want to ensure that start dates fall on Sundays and end dates fall on Saturdays. (Alternatively, enter a start date and the number of weeks to be plotted in the form instead of two dates). You would then change the query to accept @date2 as the end date (in the same way that @date1 is set to the start date). When checking dates in the query, it currently checks that dates are in the required year. You would change this to check that the dates fall between @date1 and @date2.
  5. There is definitely something going on. If I create a test table your code is fine mysql> SELECT id, username FROM ballot; +----+--------------+ | id | username | +----+--------------+ | 1 | habsfan4life | | 2 | demo | | 3 | habs4stanley | | 4 | habsfan4life | | 5 | demo | +----+--------------+ 5 rows in set (0.00 sec) mysql> SELECT username, COUNT(*) -> FROM ballot -> GROUP BY username; +--------------+----------+ | username | COUNT(*) | +--------------+----------+ | demo | 2 | | habs4stanley | 1 | | habsfan4life | 2 | +--------------+----------+ 3 rows in set (0.00 sec)
  6. If you don't, the first time you try to append to it (as it does in the loop) you will get an "Undefined variable". Plus you want to make sure it is empty before you start appending.
  7. Your usernames appear have weird non-printing characters in them which is preventing the correct ordering. Copy/pasted one of your usernames into this script $username = '​habs4stanley '; var_dump($username); echo '<br>'; for ($i=0, $k=strlen($username); $i<$k; $i++) { printf('%2X ', ord($username[$i])); } and the result was string(16) "​habs4stanley " E2 80 8B 68 61 62 73 34 73 74 61 6E 6C 65 79 20
  8. That looks more like a requirements specification than a request for help. What have you tried so far to vary the dates? Do you have a form?
  9. Your output is missing "<table>..</table> tags. You should have a structure like below, where all the <tr>..</tr> rows are inside a table <table> <tr> <td>User1</td> <td>5</td> </tr> <tr> <td>User2</td> <td>3</td> </tr> </table> Better to learn HTML before embarking on PHP
  10. You need "2017/02" to convert it to a valid timestamp
  11. try $data = "Id Name Rd Mstr Prnt Roch Rwch PPrnt PBlkRemain -----VV_WWN----- -----CreationTime------ 0 admin RW 2/3/1 --- --- --- --- -- 500name0405 2007-03-02 12:35:19 EST 1112 name.boot RW 2/3/1 --- --- --- --- -- 50002name0405 2012-02-24 16:54:48 EST 1113 name.0 RW 3/2/1 --- --- --- --- -- 5000name90405 2012-02-24 17:16:23 EST 1171 name.1 RW 1/3/2 --- --- --- --- -- 5000name405 2012-10-29 17:25:17 EDT 1306 name.boot RW 1/2/3 --- --- --- --- -- 50002name0405 2014-04-10 02:44:31 EDT 1307 name.boot RW 1/2/3 --- --- --- --- -- 5000name405 2014-04-10 08:49:09 EDT 1308 name.boot RW 1/2/3 --- --- --- --- -- 5000name0405 2014-04-10 08:50:00 EDT 0 total "; $arr = explode("\n", $data); unset($arr[0]); // remove headings foreach ($arr as $line) { $items = sscanf($line, '%d %s %s'); trim($items[1]); if (empty($items[1]) || $items[1]=='total') continue; echo $items[1] . '<br>'; $fdata[] = $items[1]; } echo '<pre>',print_r($fdata, true),'</pre>'; gives admin name.boot name.0 name.1 name.boot name.boot name.boot Array ( [0] => admin [1] => name.boot [2] => name.0 [3] => name.1 [4] => name.boot [5] => name.boot [6] => name.boot )
  12. I don't know where that comes from. There is no "total" in the data you posted.
  13. foreach ($xml2->xpath('//item') as $i) { $a1[(string)$i->q_id] = (int)$i->value; } the code scans all the items in the xml data and stores them in an array with the id as the key. If you add "q_name" then the values will be changed to arrays containing the name and the value $xml1 = simplexml_load_file('q1.xml'); $xml2 = simplexml_load_file('q2.xml'); $a1 = []; foreach ($xml1->xpath('//item') as $i) { $a1[(string)$i->q_id] = ['name' => (string)$i->q_name, 'value' => (int)$i->value]; } $a2 = []; foreach ($xml2->xpath('//item') as $i) { $a2[(string)$i->q_id] = ['name' => (string)$i->q_name, 'value' => (int)$i->value]; } foreach ($a1 as $id => $v) { echo $id . '<br>'; echo (string)$v['name'] . '<br>'; $result = $v['value'] - $a2[$id]['value']; echo $result . '<br><br>'; }
  14. I'd use sscanf $data = "Id Name Rd Mstr Prnt Roch Rwch PPrnt PBlkRemain -----VV_WWN----- -----CreationTime------ 0 admin RW 2/3/1 --- --- --- --- -- 500name0405 2007-03-02 12:35:19 EST 1112 name.boot RW 2/3/1 --- --- --- --- -- 50002name0405 2012-02-24 16:54:48 EST 1113 name.0 RW 3/2/1 --- --- --- --- -- 5000name90405 2012-02-24 17:16:23 EST 1171 name.1 RW 1/3/2 --- --- --- --- -- 5000name405 2012-10-29 17:25:17 EDT 1306 name.boot RW 1/2/3 --- --- --- --- -- 50002name0405 2014-04-10 02:44:31 EDT 1307 name.boot RW 1/2/3 --- --- --- --- -- 5000name405 2014-04-10 08:49:09 EDT 1308 name.boot RW 1/2/3 --- --- --- --- -- 5000name0405 2014-04-10 08:50:00 EDT"; $arr = explode("\n", $data); unset($arr[0]); // remove headings foreach ($arr as $line) { $items = sscanf($line, '%d %s %s'); echo $items[1] . '<br>'; }
  15. Have you checked the xml files - is 4131001 in both of them?
  16. That's because you have nested the loops. Do something like this $xml1 = simplexml_load_file('q1.xml'); $xml2 = simplexml_load_file('q2.xml'); $a1 = []; foreach ($xml1->xpath('//item') as $i) { $a1[(string)$i->q_id] = (int)$i->value; } $a2 = []; foreach ($xml2->xpath('//item') as $i) { $a2[(string)$i->q_id] = (int)$i->value; } foreach ($a1 as $id => $v) { echo $id . '<br>'; $result = $v - $a2[$id]; echo $result . '<br>'; }
  17. Another option, instead of the "active" flag is to hold "valid_from" and "valid_to" dates, then SELECT url FROM offerTable WHERE offerCode = :oCode AND CURDATE() BETWEEN valid_from AND valid_to
  18. Select the data you want to output with a WHERE clause SELECT dt, people, c_fname, c_lname, c_phone, c_notes, code FROM restaurantbooking_bookings WHERE dt BETWEEN CURDATE() AND CURDATE() + INTERVAL 3 DAY ORDER BY dt
  19. My apologies to you, creating from format will create a usable date object. Put it down to my early morning low caffeine levels. (I guess my comment is still a valid warning not to format dates until final output. Work with yyy-mm-dd.)
  20. Don't resurrect old posts. $s and $e are the start and end angles of the arc, as imagearc() in the manual would tell you. The text is centred on the midpoint of the arc. (NOTE: the angles for the text are in a clockwise direction, whereas for imagearc they are anticlockwise) Some of the lines were out of order in that old post, so I have changed the top few lines <?php /********************************************* * Fitting text to arc * * TextOnArc * Author : Barand August2007 **********************************************/ $im = imagecreate(400,400); $white = imagecolorallocate($im, 0xFF, 0xFF, 0xFF); $grey = imagecolorallocate($im, 0xCC, 0xCC, 0xCC); $txtcol = imagecolorallocate($im, 0xFF, 0x00, 0x00); $r = 150; $cx = 200; $cy = 200; $txt1 = 'Text on an Arc'; $txt2 = 'by Barand'; $font = 'c:/windows/fonts/arial.ttf'; $size = 48; $pad = 2; // extra char spacing for text $s = 180; $e = 360; imagearc($im,$cx,$cy,$r*2,$r*2,$s,$e,$grey); textOnArc($im,$cx,$cy,$r,$s,$e,$txtcol,$txt1,$font,$size,$pad); $s = 90; $e = 90; $pad = 3; // extra char spacing for text $size = 24; textInsideArc($im,$cx,$cy,$r,$s,$e,$txtcol,$txt2,$font,$size,$pad); header("content-type: image/png"); imagepng($im); imagedestroy($im); function textWidth($txt, $font, $size) { $bbox = imagettfbbox($size,0,$font,$txt); $w = abs($bbox[4]-$bbox[0]); return $w; } function textOnArc($im,$cx,$cy,$r,$s,$e,$txtcol,$txt,$font,$size, $pad=0) { $tlen = strlen($txt); $arccentre = ($e + $s)/2; $total_width = textWidth($txt, $font, $size) - ($tlen-1)*$pad; $textangle = rad2deg($total_width / $r); $s = $arccentre - $textangle/2; $e = $arccentre + $textangle/2; for ($i=0, $theta = deg2rad($s); $i < $tlen; $i++) { $ch = $txt{$i}; $tx = $cx + $r*cos($theta); $ty = $cy + $r*sin($theta); $dtheta = (textWidth($ch,$font,$size))/$r; $angle = rad2deg(M_PI*3/2 - ($dtheta/2 + $theta) ); imagettftext($im, $size, $angle, $tx, $ty, $txtcol, $font, $ch); $theta += $dtheta; } } function textInsideArc($im,$cx,$cy,$r,$s,$e,$txtcol,$txt,$font,$size, $pad=0) { $tlen = strlen($txt); $arccentre = ($e + $s)/2; $total_width = textWidth($txt, $font, $size) + ($tlen-1)*$pad; $textangle = rad2deg($total_width / $r); $s = $arccentre - $textangle/2; $e = $arccentre + $textangle/2; for ($i=0, $theta = deg2rad($e); $i < $tlen; $i++) { $ch = $txt{$i}; $tx = $cx + $r*cos($theta); $ty = $cy + $r*sin($theta); $dtheta = (textWidth($ch,$font,$size)+$pad)/$r; $angle = rad2deg(M_PI/2 - ($theta - $dtheta/2)); imagettftext($im, $size, $angle, $tx, $ty, $txtcol, $font, $ch); $theta -= $dtheta; } } ?>
  21. You cannot compare dates in "January 2nd 1970" format. For example, April 30th 2015 is less than the above date. You have to use yyyy-mm-dd format to correctly complare.
  22. I need to know a couple of things before I can give you an answer. How are you outputting them to the page (the code)? What are the structures of those two tables?
  23. to do the same without the join() you could $tableHeads = '<tr>'; foreach ($names as $n) { $tableHeads .= "<th>$n</th>"; } $tableHeads .= '</tr>'; echo $tableHeads;
  24. Does that return TRUE for blue because there is more than blue, or because you have head,body,feet all blue?
  25. Easiest way to get the form fields is to use serialize(). Try this example testing.html <html> <head> <title>Example</title> <script src="//ajax.googleapis.com/ajax/libs/jquery/1.11.0/jquery.min.js"></script> <script type='text/javascript'> $().ready(function() { $('#BtnInserisci').click(function() { var formdata = $("#form1").serialize(); $.post( "testing.php", formdata, function(html) { $('#BtnInserisci').before(html); }, 'html' ) }) }) </script> </head> <body> <form id='form1'> Field 1: <input type='text' name='field1' value='aaaa'><br> Field 2: <input type='text' name='field2' value='bbbb'><br> Field 3: <input type='text' name='field3' value='cccc'><br> <input type='button' name='BtnInserisci' id='BtnInserisci' value='Test'> </form> </body> </html> testing.php <?php $html = ''; if ($_SERVER['REQUEST_METHOD']=='POST') { $html = '<div style="width: 200px; border: 1px solid gray; margin:10px;padding:5px">'; foreach ($_POST as $k => $v) { $html .= "<p>$k : $v</p>"; } $html .= "</div>\n"; } echo $html; ?>
×
×
  • 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.