-
Posts
24,563 -
Joined
-
Last visited
-
Days Won
822
Everything posted by Barand
-
try this function <?php /******************************************** * Derive ordinal suffix for $n * * @param int $n the number * @returns string number with suffix eg 23rd */ function ordinal($n) { $str = "$n"; $t = $n > 9 ? substr($str,-2,1) : 0; $u = substr($str,-1); if ($t==1) return $str . 'th'; else switch ($u) { case 1: return $str . 'st'; case 2: return $str . 'nd'; case 3: return $str . 'rd'; default: return $str . 'th'; } } ?> examples... echo ordinal(1).'<br>'; // 1st echo ordinal(11).'<br>'; // 11th echo ordinal(101).'<br>'; // 101st echo ordinal(2).'<br>'; // 2nd echo ordinal(3).'<br>'; // 3rd echo ordinal(8).'<br>'; // 8th
-
scraping from a page using file_get_contents and preg_match_all
Barand replied to wilsoc31's topic in PHP Coding Help
Yes - DOMDocument, which you should have. $dom = new DOMDocument; $dom->loadHTML($htmlSection); foreach ($dom->getElementsByTagname('td') as $el) { echo $el->nodeValue . '<br>'; } -
scraping from a page using file_get_contents and preg_match_all
Barand replied to wilsoc31's topic in PHP Coding Help
Try simple_html_dom include('simple_html_dom.php'); $htmlSection = <<<HTML <table style="text-align: left; width: 100%;" border="0" cellpadding="2" cellspacing="0"> <tr><td style="width: 275px;"><a href="/test1.html?ti=1327"><b><span style="color: #AB1717;">2023 NSA AUTUMN BY THE SEA - 1ST/2ND PLACE TEAMS WIN BOWNET PRIZE PACK </span></b></a></td><td style="width: 225px;">MAD BCH ROC/STARKEY RANCH</td><td style="width: 100px;">MAD BCH/TRINITY</td><td style="width: 15px;">2023-09-23</td><td style="width: 15px;">2023-09-24</td><td style="width: 50px;">8U - 18U</td></tr><tr><td style="width: 275px;"><a href="/test1.html?ti=1326"><b><span style="color: #AB1717;">2023 NSA LIGHT OF AUBRIEN SCHOLARSHIP TOURNAMENT</span></b></a></td><td style="width: 225px;">BLACKSTONE PARK</td><td style="width: 100px;">PALMETTO</td><td style="width: 15px;">2023-09-23</td><td style="width: 15px;">2023-09-24</td><td style="width: 50px;">8U - 18U</td></tr><tr><td style="width: 275px;"><a href="/test1.html?ti=1328"><b><span style="color: #AB1717;">2023 NSA LADY BOMBERS LESLEY JOHNSON 4TH ANNUAL MEMORIAL TOURNAMENT - 4 SEED INTO SINGLE ELIM</span></b></a></td><td style="width: 225px;">EC MOORE/NEW TAMPA COMM PARK</td><td style="width: 100px;">CLEARWATER/NEW TAMPA</td><td style="width: 15px;">2023-09-30</td><td style="width: 15px;">2023-10-01</td><td style="width: 50px;">8U - 18U</td></tr><tr><td style="width: 275px;"><a href="/test1.html?ti=1329"><b><span style="color: #AB1717;">2023 NSA BATTLE FOR THE DOLLAR - WIN $$$ - EVERY TEAM WILL HAVE A CHANCE TO WIN CASH!</span></b></a></td><td style="width: 225px;">STARKEY RANCH</td><td style="width: 100px;">TRINITY</td><td style="width: 15px;">2023-10-07</td><td style="width: 15px;">2023-10-08</td><td style="width: 50px;">8U - 18U</td></tr><tr><td style="width: 275px;"><a href="/test1.html?ti=1330"><b><span style="color: #AB1717;">2023 NSA/ST LEO REP THE ROAR TOURNAMENT - 1ST PLACE WINS BUSCH GARDENS SEASON PASSES!</span></b></a></td><td style="width: 225px;">EC MOORE/MAD BCH ROC</td><td style="width: 100px;">CLEARWATER/MAD BCH</td><td style="width: 15px;">2023-10-14</td><td style="width: 15px;">2023-10-15</td><td style="width: 50px;">8U - 14U</td></tr><tr><td style="width: 275px;"><a href="/test1.html?ti=1331"><b><span style="color: #AB1717;">2023 NSA/ST LEO REVERSE EXPOSURE INVITATIONAL</span></b></a></td><td style="width: 225px;">EC MOORE</td><td style="width: 100px;">CLEARWATER</td><td style="width: 15px;">2023-10-14</td><td style="width: 15px;">2023-10-15</td><td style="width: 50px;">14U - 18U</td></tr><tr><td style="width: 275px;"><a href="/test1.html?ti=1333"><b><span style="color: #AB1717;">2023 NSA KING OF THE HILL - 3 SEED INTO DOUBLE ELIM - 1ST PLACE WINS HOWL-O-SCREAM TICKETS!!</span></b></a></td><td style="width: 225px;">EC MOORE/MAD BCH ROC</td><td style="width: 100px;">CLEARWATER/MAD BCH</td><td style="width: 15px;">2023-10-21</td><td style="width: 15px;">2023-10-22</td><td style="width: 50px;">8U - 18U</td></tr><tr><td style="width: 275px;"><a href="/test1.html?ti=1332"><b><span style="color: #AB1717;">2023 NSA PALMETTO SCARED HITLESS - 1ST PLACE WINS HOWL-O-SCREAM TICKETS!!</span></b></a></td><td style="width: 225px;">BLACKSTONE PARK</td><td style="width: 100px;">PALMETTO</td><td style="width: 15px;">2023-10-21</td><td style="width: 15px;">2023-10-22</td><td style="width: 50px;">8U - 18U</td></tr><tr><td style="width: 275px;"><a href="/test1.html?ti=1334"><b><span style="color: #AB1717;">2023 NSA BOMBERWEEN - COSTUME CONTEST - PUMPKIN PRIZES!!</span></b></a></td><td style="width: 225px;">EC MOORE</td><td style="width: 100px;">CLEARWATER</td><td style="width: 15px;">2023-10-28</td><td style="width: 15px;">2023-10-29</td><td style="width: 50px;">8U - 18U</td></tr><tr><td style="width: 275px;"><a href="/test1.html?ti=1335"><b><span style="color: #AB1717;">2023 NSA 13TH ANNUAL PITCH FOR THE CURE - OVER 80 TEAMS LAST YR - 4 SEED/SINGLE ELIM!</span></b></a></td><td style="width: 225px;">EC MOORE</td><td style="width: 100px;">CLEARWATER</td><td style="width: 15px;">2023-11-04</td><td style="width: 15px;">2023-11-05</td><td style="width: 50px;">8U - 18U</td></tr><tr><td style="width: 275px;"><a href="/test1.html?ti=1337"><b><span style="color: #AB1717;">2023 NSA FALL BRAWL - 1ST PLACE WINS BUSCH GARDENS TICKETS!!</span></b></a></td><td style="width: 225px;">555 COMPLEX</td><td style="width: 100px;">BARTOW</td><td style="width: 15px;">2023-11-11</td><td style="width: 15px;">2023-11-12</td><td style="width: 50px;">8U - 18U</td></tr><tr><td style="width: 275px;"><a href="/test1.html?ti=1336"><b><span style="color: #AB1717;">2023 NSA FALL BRAWL - 3 SEED INTO DOUBLE ELIMINATION!!</span></b></a></td><td style="width: 225px;">STARKEY RANCH</td><td style="width: 100px;">TRINITY</td><td style="width: 15px;">2023-11-11</td><td style="width: 15px;">2023-11-12</td><td style="width: 50px;">8U - 18U</td></tr><tr><td style="width: 275px;"><a href="/test1.html?ti=1338"><b><span style="color: #AB1717;">2023 NSA BATTERBALL TURKEYFEST - DOUBLE/DOUBLE - 1ST & 2ND PLACE WIN NEW GLOVES!!</span></b></a></td><td style="width: 225px;">BLACKSTONE PARK</td><td style="width: 100px;">PALMETTO</td><td style="width: 15px;">2023-11-18</td><td style="width: 15px;">2023-11-19</td><td style="width: 50px;">8U - 18U</td></tr><tr><td style="width: 275px;"><a href="/test1.html?ti=1339"><b><span style="color: #AB1717;">2023 NSA BATTERBALL TURKEYFEST - DOUBLE/DOUBLE - 1ST & 2ND PLACE WIN NEW GLOVES!!</span></b></a></td><td style="width: 225px;">MAD BCH ROC/STARKEY RANCH</td><td style="width: 100px;">MAD BCH/TRINITY</td><td style="width: 15px;">2023-11-18</td><td style="width: 15px;">2023-11-19</td><td style="width: 50px;">8U - 18U</td></tr><tr><td style="width: 275px;"><a href="/test1.html?ti=1340"><b><span style="color: #AB1717;">2023 NSA THANKSGIVING THROWDOWN - 1 DAY/SUNDAY ONLY EVENT!!</span></b></a></td><td style="width: 225px;">NEW TAMPA COMM PARK</td><td style="width: 100px;">NEW TAMPA</td><td style="width: 15px;">2023-11-26</td><td style="width: 15px;">2023-11-26</td><td style="width: 50px;">8U - 18U</td></tr><tr><td style="width: 275px;"><a href="/test1.html?ti=1341"><b><span style="color: #AB1717;">2023 NSA TOYS FOR TOTS #1 - 1ST & 2ND PLACE WIN NEW GLOVES!!</span></b></a></td><td style="width: 225px;">MADEIRA BEACH ROC</td><td style="width: 100px;">MADEIRA BEACH</td><td style="width: 15px;">2023-12-02</td><td style="width: 15px;">2023-12-03</td><td style="width: 50px;">8U - 18U</td></tr><tr><td style="width: 275px;"><a href="/test1.html?ti=1342"><b><span style="color: #AB1717;">2023 NSA FALL STATE CHAMPIONSHIPS - REDEEM THE $$ YOU EARNED EACH TOURNAMENT THIS FALL!!</span></b></a></td><td style="width: 225px;">MULTIPLE VENUES</td><td style="width: 100px;">POLK COUNTY</td><td style="width: 15px;">2023-12-09</td><td style="width: 15px;">2023-12-10</td><td style="width: 50px;">8U - 18U</td></tr><tr><td style="width: 275px;"><a href="/test1.html?ti=1343"><b><span style="color: #AB1717;">2023 NSA TOYS FOR TOTS #2 - CHANCE TO WIN SOME PRESENTS & COME MEET SANTA!!</span></b></a></td><td style="width: 225px;">NEW TAMPA COMM PARK</td><td style="width: 100px;">NEW TAMPA</td><td style="width: 15px;">2023-12-16</td><td style="width: 15px;">2023-12-17</td><td style="width: 50px;">8U - 18U</td></tr> </table> HTML; $dom = str_get_html($htmlSection); foreach($dom->find("td") as $el) { echo $el->innertext . '<br>'; } giving etc. -
Real time Java script calculation for update Row & column total
Barand replied to Senthilkumar's topic in Javascript Help
Try my tutorial... http://barringtondrew.co.uk/?page=3&tut=0 -
Real time Java script calculation for update Row & column total
Barand replied to Senthilkumar's topic in Javascript Help
Now you need to determine the relationships (if any) between model/dealer/target -
Real time Java script calculation for update Row & column total
Barand replied to Senthilkumar's topic in Javascript Help
In that case... +------------+ | category | +------------+ | id |------------+ | cat_name | | +------------+ | | +---------------+ | | subcategory | | +---------------+ | | id |------+ | | category_id | | | | subcat_name | | | +---------------+ | | | | | | | | +------------+ | | | model | | | +------------+ | | | id | | | | model_name | | +---<| category_id| +------<| subcat_id | +-----------<| brand_id | | +------------+ | +------------+ | | brand | | +------------+ | | id |----+ | brand_name | +------------+ -
Real time Java script calculation for update Row & column total
Barand replied to Senthilkumar's topic in Javascript Help
1) why, then, are they called subcategories? 2) what is the relationship between your categories and subcategories? -
Real time Java script calculation for update Row & column total
Barand replied to Senthilkumar's topic in Javascript Help
So your are saying that your subcategories do not belong to a parent category? -
Real time Java script calculation for update Row & column total
Barand replied to Senthilkumar's topic in Javascript Help
If you know the subcategory then you know the category, so you don't need both in the model table- just the subcategory id. -
Real time Java script calculation for update Row & column total
Barand replied to Senthilkumar's topic in Javascript Help
They shouldn't be. The brand name is an attribute of the brand entity. That is the only place it should be stored in your database - not duplicated across dozens of records in other tables. Only id values should appear in other tables as foreign keys. Suppose Elon Musk takes over your company and decrees that, from now on, the name "EXCAVATOR" should appear on all company web pages and reports as "X-CAVATOR". Now ask yourself "in how many places in your spreadsheet-style db tables would you have change that spelling?" In my design that answer would be 1. -
Real time Java script calculation for update Row & column total
Barand replied to Senthilkumar's topic in Javascript Help
Your model table should be four tables.. +------------+ | category | +------------+ | id |----+ | cat_name | | +------------+ | | | +---------------+ | | subcategory | | +---------------+ | | id |------+ +----<| category_id | | | subcat_name | | +---------------+ | | | | +------------+ | | model | | +------------+ | | id | | | model_name | +------<| subcat_id | +-----------<| brand_id | | +------------+ | +------------+ | | brand | | +------------+ | | id |----+ | brand_name | +------------+ -
PHP 8.1 How can I stop warning messages from displaying?
Barand replied to SLSCoder's topic in PHP Coding Help
By far the best the best way is to fix whatever they are warning you about. -
Real time Java script calculation for update Row & column total
Barand replied to Senthilkumar's topic in Javascript Help
Last time I tried to do that you ignored it... -
Real time Java script calculation for update Row & column total
Barand replied to Senthilkumar's topic in Javascript Help
You should not be storing totals. Your data should be correctly designed (normalized). Come back when it is and I'll be glad to help. -
P.S. Instead of runnning 3 queries you could do something like this SELECT string , SUM(CASE WHEN date > NOW() - interval 1 HOUR THEN 1 ELSE 0 END) as lastHour , SUM(CASE WHEN date > NOW() - interval 1 DAY THEN 1 ELSE 0 END) as lastDay , SUM(CASE WHEN date > NOW() - interval 7 DAY THEN 1 ELSE 0 END) as lastWeek FROM queries GROUP BY string; giving
-
You do realise that id and date values returned by that query could be from any arbitrary record in the group and therefore meaningless, don't you? Define "working".
-
By using a "title" attribute?
-
Example code (data from tutorial in my sig) <?php $res = $pdo->query("SELECT concat(fname, ' ', lname) as name , group_concat(subject separator '<br>') as subjects FROM pupil p JOIN choice c USING (pupilID) JOIN subject s USING (subjectID) WHERE houseID = 1 GROUP BY p.pupilID; "); $tdata = ''; foreach ($res as $row) { $tdata .= "<tr><td>{$row['name']}</td> <td>{$row['subjects']}</td> </tr>"; } ?> <!DOCTYPE html> <html lang='en'> <head> <meta charset='utf-8'> <title>Example</title> <style type='text/css'> body { font-family: verdana; } table { border-collapse: collapse; width: 500px; margin: 50px auto; } td { padding: 4px 16px; } </style> </head> <body> <table border='1'> <?= $tdata ?> </table> </body> </html> output
-
Have you got "display_startup_errors" turned on in your php.ini file?
-
Because you exit before anything can be output?
-
If you use prepared queries correctly, with placeholders for user-supplied data, you don't need that code - the values will not be embedded in the SQL code.
-
By the way, your query will not output the rooms that you want. Check the date join conditions between room and room_booking in your query against the query I gave you in your previous post. Also, the only join that may or may not find a matching record is room->room_booking, so that needs to be a LEFT JOIN. All the other joins only need to be simple JOINs (which are much faster than LEFT JOINS) SELECT rs.description , rs.sleeps , rs.image , rs.price , GROUP_CONCAT(DISTINCT f.description SEPARATOR '<br>') AS rmfac , rt.description as rmtype , r.room_id , r.room_number FROM room as r JOIN roomtype as rt ON r.roomtype_id = rt.roomtype_id JOIN roomsize as rs ON r.size_id = rs.size_id JOIN room_facility as rf ON rf.size_id = rs.size_id JOIN facility as f ON rf.facility_id = f.facility_id LEFT JOIN room_booking as rb ON r.room_id = rb.room_id AND rb.departureDate > :arrival AND rb.arrivalDate <= :departure WHERE rb.room_id IS NULL ORDER BY room_id