-
Posts
24,566 -
Joined
-
Last visited
-
Days Won
822
Everything posted by Barand
-
Is it Sunday?. It was no great hardship for me, merely bringing it to someone's notice. I was just trying to get the back-story on someone's recent post to find out what they were talking about. Please, don't stop work on my account.
-
I am unable to find anything using "Search". Similarly, clicking a members "Find Content" button shows no results.
-
How about putting a FROM clause in your query to tell it which table the data is to come from.
-
group by month and year with this format "01/29/2016"
Barand replied to Yohanne's topic in MySQL Help
Use str_to_date() to convert your format to to DATE type. Then you can use the other datetime functions on it. EG SELECT YEAR(STR_TO_DATE(datestr, '%m/%d/%Y')) as yr , MONTH(STR_TO_DATE(datestr, '%m/%d/%Y')) as mth , COUNT(*) as total FROM mytable GROUP BY yr, mth You can use the same function to update your database table with a single query. Backup the table, just in case UPDATE mytable SET datestr = STR_TO_DATE(datestr, '%m/%d/%Y'); Alter varchar to DATE -
This function will return week number 1 or 2 for a given date (today being in week 1 and changing each sunday) function myWeekNumber(DateTime $date) { $base = new dateTime('2000-01-01'); // Fixed Saturday date return ceil($date->diff($base)->days/7) % 2 + 1; }
-
Unfortunately you can have week 53 followed by week 1, so two consecutive odd week numbers. Safer to use the number of weeks elapsed from a fixed date in the past.
-
Commonly known as "Hungarian Notation" https://en.wikipedia.org/wiki/Hungarian_notation
-
Getting sum of a column from a table into a textbox
Barand replied to lindisfarne's topic in PHP Coding Help
Are you referring to an input box of type "text" or a textarea element? If the former then using the value attribute should work. echo "<input type='text' name='total' value='$total' />"; If you mean the latter then there is no value attribute. The text content goes between the open and close tags echo "<textarea rows='2' cols='20' name='total'>$total</textarea>"; Basic HTML. And please use code tags, or the "<>" button in the toolbar. -
A homeless snail ?
-
This closes off any current tags $text = "<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Etiam elementum ornare scelerisque.<br> <a href='xyz.com' target='_blank'>Vestibulum</a> iaculis mattis dui.</p> <p>Aliquam <i>scelerisque</i> sapien at tellus accumsan varius. <img src='a.jpg'> Fusce facilisis ullamcorper dapibus. Aliquam dignissim</p> <ul> <li>gravida</li> <li>dui eget</li> <li>aliquam</li> </ul> <p>Duis odio, semper eu sodales vel, sollicitudin eu enim. Cras tortor libero, pellentesque accumsan tempus in, ullamcorper nec augue. Mauris eu ipsum mauris, non imperdiet ipsum. In hac habitasse platea dictumst. Morbi ipsum mauris, tincidunt vitae pretium tempor, pretium a turpis. Nulla quis eros eu lorem aliquam congue non a nisl.</p>"; $voidtags = ['br','hr','img']; $keeptags = '<a><b><i><br><p><ul><ol><li><u><strong><emphasis>'; $limit = 30; $summary = limitText($text, $limit, $voidtags, $keeptags); echo $summary; function limitText($text, $limit, $voidtags, $keeptags) { $result = ''; $p=0; $tags=[]; $currtag = ''; $words = 0; $intag = $inword = 0; $text = strip_tags($text, $keeptags); $len = strlen($text); while ($p<$len) { $c = $text[$p]; switch ($c) { case '<': if ($inword) { $inword = 0; $words++; if ($words > $limit) break 2; } $intag = 1; break; case '>': if ($intag && $currtag != '') { if (!in_array($currtag, $voidtags)) $tags[] = $currtag; $currtag = ''; } $intag = 0; break; case '/': if ($intag) { array_pop($tags); do { $result .= $c; } while (($c=$text[++$p]) !='>'); $intag = 0; } break; case "\n": case "\t": case ' ': if ($inword) { $inword = 0; $words++; if ($words >= $limit) break 2; } elseif ($intag) { $tags[] = $currtag; do { $result .= $c; } while (($c=$text[++$p]) !='>'); $intag = 0; } break; default: if ($intag) { $currtag .= $c; } else $inword = 1; break; } $result .= $c; ++$p; } while ($t=array_pop($tags)) { $result .= "</{$t}>"; // close any open tags } return $result; } results <p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Etiam elementum ornare scelerisque.<br> <a href="xyz.com" target="_blank">Vestibulum</a> iaculis mattis dui.</p> <p>Aliquam <i>scelerisque</i> sapien at tellus accumsan varius. Fusce facilisis ullamcorper dapibus. Aliquam dignissim</p> <ul> <li>gravida</li> <li>dui</li></ul>
-
So, if I understand you, there is an array ($subcats) which you implode into a comma separated string and which you now want to put back into an array. But you already have that array - $subcats
-
I can't remember when I last received an email notification from this site. I should also receive notifications in the bar at the top of the screen when a new topic is posted in the MySQL forum, but my last notification of any kind was Oct 8th, despite a new MySQL topic yesterday.
-
Thanks, I have been worrying about that for the last nine years.
-
why my explode and str_split code is not working?
Barand replied to Michael_Baxter's topic in PHP Coding Help
The error is on line 116. -
Rework a cal-sheet gear calculation from mp/h to km/h
Barand replied to Maze's topic in Miscellaneous
multiply by 1.60934 -
When I worked on intranets with active directory, I found that the excellent ADLDAP class took the pain away. http://adldap.sourceforge.net/
- 2 replies
-
- ldap
- authentication
-
(and 2 more)
Tagged with:
-
this doesn't use regex but mysql> SELECT id -> , name -> , phone -> , CASE -> WHEN SUBSTRING(phone,1,1)='0' -> THEN CONCAT('(353)',SUBSTRING(phone,2)) -> ELSE phone -> END as phone2 -> FROM contact; +----+-------------+-------------+-----------------+ | id | name | phone | phone2 | +----+-------------+-------------+-----------------+ | 1 | aaaaaaaaa | 12345674321 | 12345674321 | | 2 | bbbbbbbb | NULL | NULL | | 3 | cccccccc | 01214567890 | (353)1214567890 | | 4 | dddddd | NULL | NULL | | 5 | eeeeeeeeeee | 09087654321 | (353)9087654321 | | 6 | kkkkkkkkk | NULL | NULL | | 7 | mmmm | NULL | NULL | +----+-------------+-------------+-----------------+
-
mysql query not working with drop down boxes
Barand replied to lindisfarne's topic in PHP Coding Help
COBOL? - can't be many of us left. Although I haven't used it since around 1980. -
You need to calculate how many days from now to the recurrence of the next weekday for any recurring events. So if it's a weekly event on mondays then the next will be three days from now. So if we have mysql> select * from event order by start_date; +----------+---------------+------------+------------------+--------+ | event_id | event_name | start_date | event_venue | recurs | +----------+---------------+------------+------------------+--------+ | 2 | Halle concert | 2016-07-01 | Bridgewater Hall | WEEKLY | | 4 | PHP Group | 2016-08-10 | Greyhound Inn | WEEKLY | | 1 | Flower show | 2016-09-08 | Tatton Park | ONCE | | 3 | Rock festival | 2016-10-22 | Bramall Hall | ONCE | +----------+---------------+------------+------------------+--------+ then we can get the next events with SELECT event_name , recurs , start_date , DAYNAME(start_date) as day , CASE recurs WHEN 'WEEKLY' THEN CURDATE() + INTERVAL (7 + WEEKDAY(start_date) - WEEKDAY(CURDATE())) DAY WHEN 'ONCE' THEN start_date END as next_date FROM event HAVING next_date > CURDATE() ORDER BY next_date; +---------------+--------+------------+-----------+------------+ | event_name | recurs | start_date | day | next_date | +---------------+--------+------------+-----------+------------+ | PHP Group | WEEKLY | 2016-08-10 | Wednesday | 2016-10-05 | | Halle concert | WEEKLY | 2016-07-01 | Friday | 2016-10-07 | | Rock festival | ONCE | 2016-10-22 | Saturday | 2016-10-22 | +---------------+--------+------------+-----------+------------+
-
You are not going to accomplish anything that relies on date sequencing with your dates in that format. You need to use DATETIME type column with format of YYYY-MM-DD HH-ii_ss so the dates are sortable.
-
mysql query not working with drop down boxes
Barand replied to lindisfarne's topic in PHP Coding Help
I spoonfed you code and you still got it wrong Don't give up the day job. If you look at the code I gave you, the line outputting the code is after the end of the while() loop. You have include that line within the loop, which is why it keeps repeating. -
mysql query not working with drop down boxes
Barand replied to lindisfarne's topic in PHP Coding Help
post the code that produced that output -
Solution posted in your other topic with this code https://forums.phpfreaks.com/topic/302251-mysql-query-not-working-with-drop-down-boxes/?do=findComment&comment=1537892
-
mysql query not working with drop down boxes
Barand replied to lindisfarne's topic in PHP Coding Help
It isn't difficult - add three lines of code, as I told you $total = 0; // initialise total while($record = mysql_fetch_array($myData)){ echo "<tr>"; echo "<td>" . $record['id'] . "</td>"; echo "<td>" . $record['author'] . "</td>"; echo "<td>" . $record['title'] . "</td>"; echo "<td>" . $record['publisher'] . "</td>"; echo "<td>" . $record['year'] . "</td>"; echo "<td>" . $record['genre'] . "</td>"; echo "<td>" . $record['sold'] . "</td>"; echo "<tr />"; $total += $record['sold']; // accumulate total } echo "<tr><td colspan='6'>Total:</td><td>$total</td></tr>"; // output total echo "</table>";