Jump to content

Barand

Moderators
  • Posts

    24,563
  • Joined

  • Last visited

  • Days Won

    822

Everything posted by Barand

  1. 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
  2. Yes - DOMDocument, which you should have. $dom = new DOMDocument; $dom->loadHTML($htmlSection); foreach ($dom->getElementsByTagname('td') as $el) { echo $el->nodeValue . '<br>'; }
  3. 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.
  4. Try my tutorial... http://barringtondrew.co.uk/?page=3&tut=0
  5. Now you need to determine the relationships (if any) between model/dealer/target
  6. 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 | +------------+
  7. 1) why, then, are they called subcategories? 2) what is the relationship between your categories and subcategories?
  8. So your are saying that your subcategories do not belong to a parent category?
  9. If you know the subcategory then you know the category, so you don't need both in the model table- just the subcategory id.
  10. 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.
  11. 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 | +------------+
  12. By far the best the best way is to fix whatever they are warning you about.
  13. Last time I tried to do that you ignored it...
  14. 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.
  15. 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
  16. 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".
  17. By using a "title" attribute?
  18. 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
  19. Have you got "display_startup_errors" turned on in your php.ini file?
  20. Because you exit before anything can be output?
  21. 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.
  22. To check for rooms booke between dates A and B you need to compare their departureDate against A, and arrivalDate against B Your query above has ... * * * * * The <br> won't kick in until you you output to an HTML page.
  23. 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
  24. Perhaps because your separator is "\n" and HTML treats all whitespace as a space. Try "<br>";
  25. When you use an agregation function (like SUM() or GROUP_CONCAT() ) without a GROUP BY clause, you get a single aggregation for the whole table.
×
×
  • 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.