-
Posts
24,563 -
Joined
-
Last visited
-
Days Won
822
Everything posted by Barand
-
Start 6 months from current date then every 6 months. Spring if in first half of the year, Fall otherwise $today = '2014-07-01'; // used to set todays date for testing $dt1 = new DateTime($today); $dt1->add(new DateInterval('P6M')); $dt2 = clone $dt1; $dt2->add(new DateInterval('P5Y')); $dp = new DatePeriod($dt1, new DateInterval('P6M'), $dt2); // dates every 6 months for 5 years foreach ($dp as $d) { echo $d->format("Y "); if (1 <= $d->format('n') && $d->format('n') <= 6) { echo "Spring<br>"; } else { echo "Fall<br>"; } }
- 5 replies
-
- 3
-
- date exclusion
- date
-
(and 3 more)
Tagged with:
-
Use the DATE() function which returns just the date portion of a datetime field eg WHERE DATE(mydatefield) = '2014-09-18'
-
I usually produce my own "hand-rolled" charts. As production of a chart usually requires data from a DB server I produce them server-side using PHP, either as an image or using vector graphics. Producing them on the server with PHP does not preclude interaction with the user. If I require an interactive chart then I use SVG which allows me to assign mouse events to the various graphic elements (eg rectangles, circles). Of course you can make an image interactive with an image map but SVG makes it a lot easier.
-
When you specify users for a MySql database you can also specify the domains from which they are allowed to access the server (or specify "%" as wildcard meaning anywhere). It sounds as though that IP is not valid for that username. You need to change the user access credentials to allow that IP address, or get an admin to do it.
-
Your sin is not showing us what the function does and how it is being called.
-
Delete lines 2 and 3. Just fetch and output with the while() loop. $results = mysqli_query($con, "SELECT * FROM Entries ORDER BY PID DESC LIMIT 0,8"); while ($rowFp = mysqli_fetch_array($results)) { echo "<br /><br />" . $rowFp['Title'] . "<br />" . $rowFp['remoteTime'] . "<br /><br />" . $rowFp['PID']; }
-
Mouse clicks are handled by the browser on the client after PHP has finished executing on the server so you cannot call a PHP function directly in response to a mouse event. If you don't want to go to another page then you need to use AJAX. You should Google AJAX to find out more but, basically, you use a javascript function to send a request message to a PHP script the server in response to the click. The script executes and sends data back to the calling function which then displays it on the page.
-
@ginerjm That's weird while() syntax you're using there
-
I think you need to quote the keys and string values in your json array Try 'items' => '{"id":123,"species":"stud","at":"keepsake"}',
-
Better to use a foreach() loop $db = new mysqli(HOST,USERNAME,PASSWORD,DATABASE); $sql = "INSERT INTO tbl_lg_rider_order (`name`,`card_id`,`homeaway`,`riderorder`) VALUES (?,?,?,?)"; $stmt = $db->prepare($sql); $stmt->bind_param('siss', $name,$card_id,$ha,$rideorder); foreach ($home_rider as $k => $name) { $ha = 'h'; $rideorder = $order[$k]; $stmt->execute(); } foreach ($away_rider as $k => $name) { $ha = 'a'; $rideorder = $awayorder[$k]; $stmt->execute(); }
-
your for() syntax is wrong http://uk1.php.net/manual/en/control-structures.for.php
-
Does it work if you assign xmlhttp.responseText instead?
-
Kudos to Psycho - But One Baffling Question Remaining
Barand replied to spock9458's topic in PHP Coding Help
Writing the output to a .html file then opening that file in Word should work -
Or store the results in an array and use array_chunk() with a chunk size of 4 EG $sql = "SELECT user_id, username FROM user ORDER BY username"; $res = $db->query($sql); $rows = $res->fetch_all(); $chunks = array_chunk($rows, 4); foreach ($chunks as $chunk) { echo "<table border='1' cellpadding='3'> <tr><th>Id</th><th>Name</th></tr>\n"; foreach ($chunk as $row) { list($id, $name) = $row; echo "<tr><td>$id</td><td>$name</td></tr>\n"; } echo "</table><br><br>\n"; }
-
Using the MOD() function on a numeric value eg "id" or TO_SECONDS(rec_date) should allow you to select approximately every Nth record ... WHERE MOD(id,20) = 0. mysql> SELECT * FROM test; 182685 rows in set (0.15 sec) mysql> SELECT * FROM test WHERE MOD(id,10)=0; 18268 rows in set (0.08 sec) Alternatively check why it takes a long time. 2048 recs is not a large dataset If you are doing lots of AJAX calls you will be incurring the overhead of connecting to the DB each time. Is it possible to accomplish the task in a single call?
-
Slow Query Running/Page Rendering While MySQL Event Is Being Executed
Barand replied to phdphd's topic in MySQL Help
As well as the table structure the query syntax used can also affect performance and, for all we know, you could be running multiple queries inside loops. You have given us absolutely no information for us to help you. -
mysqli_connnect() should only have 2 n's
-
PHP XML Attributes Parsing Resets into Array
Barand replied to mouseywings's topic in PHP Coding Help
try $data = array(); foreach ($parse->division as $div) { $key = (string)$div['id']; $val = (string)$div; $data[$key] = $val; }- 2 replies
-
- php
- xml-parsing
-
(and 2 more)
Tagged with:
-
Does this help? $points=array(); $arr = array_map('trim', explode("\n", $file)); foreach ($arr as $line) { list($n, $p) = sscanf($line, '%s %d'); if ($p) $points[$n] = $p; } arsort($points); echo '<pre>',print_r($points, true),'</pre>';
-
Slow Query Running/Page Rendering While MySQL Event Is Being Executed
Barand replied to phdphd's topic in MySQL Help
Possibly. From the information that you have given us I am sure any of the psychics on the forum could help. -
When you create the selection dropdown for music styles, use SELECT ms.idstyle , style , id_user FROM music_styles ms LEFT JOIN user_styles us ON ms.id_style = us.id_style AND us.id_user = $user Those styles with a user id should be marked as "selected"
-
you need to add parentheses echo (new DateTime('2014-09-13'))->format('d/m/Y'); //---> 13/09-2014
-
You can use something like this to loop through as many colours as want in the rows. Put the colours in an array and use $i++%$n as the index to select the row colour from the array (where $i is row counter and $n is the number of colours in the array) $sql = "SELECT username FROM user"; $res = $db->query($sql); $output = ''; $i = 0; // array of colour values $colours = array ('#80FFFF', '#50CFCF', '#209F9F'); $n = count($colours); while ($row = $res->fetch_assoc()) { $output .= "<tr><td style='background-color:{$colours[$i++%$n]}'>{$row['username']}</td></tr>\n"; } echo "<table style='border-collapse: collapse; width:150px' border='1' cellpadding='5'> $output </table>"; This example gives: