Jump to content

Barand

Moderators
  • Posts

    23,588
  • Joined

  • Last visited

  • Days Won

    707

Everything posted by Barand

  1. You think two lines of code is an over-complicated solution?
  2. If you need more detail, there is a manual for that explanation of foreach
  3. Sorry about the spelling mistake. "foreaach" should (of course) be "foreach".
  4. Easiest way is to treat $query as an array and just iterate through the results <table> <?php foreaach ($query as $row) { echo "<tr><td>" . join("</td><td>", $row) . "</td></tr>"; } ?> </table>
  5. This is exactly the same code and problm that you posted on Saturday morning and which was answered by @ginerjm telling precisely wht was wrong nd giving you the correct code... Stop repeating questions and ignoring replies.
  6. Beacause in this case, the "needle" is at position 0 evaluates to "localhost:8888" ^ pos 0
  7. Looking up strpos() in the manual would have explained exactly what your problem is, and the first example gives you the cure.
  8. Then how are managing to query it? How do you check if your query has selected the correct subset? Perhaps this might have been an idea... SELECT * FROM retirees ORDER BY birthday;
  9. That being the case, all you need is $sql = "SELECT .... FROM retirees WHERE CURDATE() = STR_TO_DATE(birthday, '%m/%d/%Y')"; Thank you for keeping that fact hidden (the sample data values you gave us did not reflect the data in the table) and wasting our time.
  10. I can't either. How many retirees do have in your table who were born today (ie 0 years old)
  11. $sql needs to be a string value. Put the query string inside single quotes. $sql = 'SELECT birthday FROM retirees WHERE MONTH(str_to_date(birthday, "%m/%d/%Y")) = MONTH(CURDATE()) AND DAYOFMONTH(str_to_date(birthday, "%m/%d/%Y")) = DAYOFMONTH(CURDATE())';
  12. It will if you tell it to. Put this line mysqli_report(MYSQLI_REPORT_ERROR|MYSQLI_REPORT_STRICT); just before your line calling $conn = new mysqli(...)
  13. The output from phpinfo() will tell which php.ini is being used In the php.ini file there will be a line defining the folder where it expects the extensions to be stored Check that is where the new extensions were installed.
  14. Edit your php.ini file and remove the ";" from the start of the lines specifying those extension EG ;extension=mbstring ^ remove Restart your server.
  15. Yes, correct. Although using SELECT * is a bad habit. Select just the columns you need
  16. There are dozens of date functions you can use once you have a date in the correct format. That was just one example. Another couple... SELECT birthday FROM testdate WHERE MONTH(str_to_date(birthday, '%m/%d/%Y')) = 10 AND DAYOFMONTH(str_to_date(birthday, '%m/%d/%Y')) = 22; +------------+ | birthday | +------------+ | 10/22/1989 | +------------+ or, if you want current day's birthdays SELECT birthday FROM testdate WHERE MONTH(str_to_date(birthday, '%m/%d/%Y')) = MONTH(CURDATE()) AND DAYOFMONTH(str_to_date(birthday, '%m/%d/%Y')) = DAYOFMONTH(CURDATE());
  17. Even if don't permanently change the formats, you can still use str_to_date() to make non-standard date formats usable by MySql date/time functions and in date comparison queries. EG SELECT birthday , date_format(str_to_date(birthday, '%m/%d/%Y'), '%W %D %M %Y') as formatted FROM testdate; +------------+---------------------------+ | birthday | formatted | +------------+---------------------------+ | 01/15/1980 | Tuesday 15th January 1980 | | 10/22/1989 | Sunday 22nd October 1989 | | 11/09/1979 | Friday 9th November 1979 | +------------+---------------------------+
  18. You can convert your varchar date to the correct Y-m-d formats using mysql's STR_TO_DATE() function eg mysql> select * from testdate; +------------+ | birthday | +------------+ | 01/15/1980 | | 10/22/1989 | | 11/09/1979 | +------------+ mysql> UPDATE testdate set birthday = str_to_date(birthday, '%m/%d/%Y'); mysql> select * from testdate; +------------+ | birthday | +------------+ | 1980-01-15 | | 1989-10-22 | | 1979-11-09 | +------------+ CAVEAT - make a copy of the table first, just in case.
  19. It looks like you gave it a painkiller instead of curing the source of the pain. You should be checking why you are calling a function (that expects an array) with a variable that isn't an array.
  20. According to the error message, $items is NULL. You need to find where your function is being called and investigate why the item being passed to the function has no value assigned, and put some checking code in to prevent it reoccurring.
  21. Alternatively, assuming they all have same rigid structure, ... $fp = file('weather.html', FILE_IGNORE_NEW_LINES|FILE_SKIP_EMPTY_LINES); $data = []; foreach ($fp as $line) { switch (substr($line, 0, 4)) { case '<!--' : if ($line[4]!=' ') { $section = substr($line, 4, -8); } break; case '<td>' : list($name, $value) = getData($line); $data[$section][$name] = $value; break; default : continue 2; } } function getData($line) { $l = substr($line, 4, -5); return explode('</td><td>', $l); } // View the results echo '<pre>' . print_r($data, 1) . '</pre>'; giving ... $data = Array ( [MISCELLANEOUS] => Array ( [Name of Station] => AzureCove [City (from NOAA Setup)] => Garden City [State (from NOAA Setup)] => Utah [Elevation (from NOAA Setup)] => 5954 ft [Latitude (from NOAA Setup)] => 41° 56' 12" N [Longitude (from NOAA Setup)] => 111° 23' 20" W [Date on the PC] => 03/13/23 [Time on the PC] => 4:06a [UTC Time] => 10:06a [UTC Date] => 03/13/23 [Date on the Station] => 03/13/23 [Time on the Station] => 4:05a [Sunrise Time] => 7:41a [Sunset Time] => 7:30p [Current Weather Forecast *] => Partly cloudy with little temperature change. [Current Moon Phase] => Last Quarter [EMC] => --- [EMC Unit] => % [Air Density] => 0.0842 [Air Density Unit] => lb/cu.ft ) [INSIDE TEMPERATURE] => Array ( [Inside Temperature] => 42.5 [High Inside Temperature] => 43.6 [Time of High Inside Temperature] => 12:00a [Low Inside Temperature] => 42.5 [Time of Low Inside Temperature] => 3:41a [High Monthly Inside Temperature] => 45.4 [Low Monthly Inside Temperature] => 39.4 [High Yearly Inside Temperature] => 45.7 [Low Yearly Inside Temperature] => 39.4 ) [OUTSIDE TEMPERATURE] => Array ( [Outside Temperature] => 15.1 [High Outside Temperature] => 21.7 [Low Outside Temperature] => 15.1 [Time of High Outside Temperature] => 12:00a [Time of Low Outside Temperature] => 4:04a [High monthly Outside Temperature] => 46.1 [Low monthly Outside Temperature] => -11.3 [High yearly Outside Temperature] => 46.1 [Low yearly Outside Temperature] => -12.5 ) . . . )
  22. SQL solution TABLE: ark TABLE: received +----+------+-----+ +----+------+-----+ | id | item | qty | | id | item | qty | +----+------+-----+ +----+------+-----+ | 1 | cow | 6 | | 1 | cow | 3 | | 2 | fish | 7 | | 2 | fish | 7 | | 4 | cat | 1 | +----+------+-----+ +----+------+-----+ SELECT a.item , coalesce(r.qty,0) as Arrived , a.qty - coalesce(r.qty,0) as `Lost in transit` FROM ark a LEFT JOIN received r USING (item) +------+---------+-----------------+ | item | Arrived | Lost in transit | +------+---------+-----------------+ | cow | 3 | 3 | | fish | 7 | 0 | | cat | 0 | 1 | +------+---------+-----------------+
  23. or $ark = array( '3 gerbils', '7 fish', '3 gerbils', '1 cat' ); $received = array( '3 gerbils', '7 fish' ); foreach($ark as $j => $expected) { echo $expected; foreach($received as $k => $line) { if($expected == $line) { echo " ARRIVED"; unset ($received[$k], $ark[$j]); // cross them off the lists } } echo "<hr>"; } giving...
  24. The cat hasn't arrived and the others have. What's wrong with that?
×
×
  • 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.