-
Posts
23,588 -
Joined
-
Last visited
-
Days Won
707
Everything posted by Barand
-
You think two lines of code is an over-complicated solution?
-
If you need more detail, there is a manual for that explanation of foreach
-
Sorry about the spelling mistake. "foreaach" should (of course) be "foreach".
-
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>
-
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.
-
Beacause in this case, the "needle" is at position 0 evaluates to "localhost:8888" ^ pos 0
-
Looking up strpos() in the manual would have explained exactly what your problem is, and the first example gives you the cure.
-
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());
-
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 | +------------+---------------------------+
-
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.
-
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.
-
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.
-
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 ) . . . )
-
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 | +------+---------+-----------------+
-
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...
-
The cat hasn't arrived and the others have. What's wrong with that?