-
Posts
24,563 -
Joined
-
Last visited
-
Days Won
822
Everything posted by Barand
-
Define $WINNERS = []; before your query. Then if there are no query results the in_array() is still valid.
-
Thank you for sharing that. Is there a question to go with it? Please use code button <> when posting code.
-
Your problem is was where to use backticks and where to use single quotes.
-
The query you ran in PHPMyAdmin appears to be the only one above that has correct syntax.
-
Unsupported operand types: int + string in after ( php 8 update)
Barand replied to Zacks's topic in PHP Coding Help
Could be one of those really useful functions that comes free with a framework eg function get_field($key) { return $_GET[$key]; } -
Unsupported operand types: int + string in after ( php 8 update)
Barand replied to Zacks's topic in PHP Coding Help
-
Unsupported operand types: int + string in after ( php 8 update)
Barand replied to Zacks's topic in PHP Coding Help
Sounds like one or more of those get_fields is an empty string. -
Apart from unnecessary field retrieval and loops, what is the nature of your problem?
-
If you take the MySQL route then use PDO to interfaace with DB. Create a connection file which can be included in your scripts. Mine is <?php #------------------------------------------------------------------------------------------+ # db_connect.php | #------------------------------------------------------------------------------------------+ const HOST = 'localhost'; const USERNAME = '????'; const PASSWORD = '????'; const DATABASE = '????'; // default db function pdoConnect($dbname=DATABASE) { $db = new PDO("mysql:host=".HOST.";dbname=$dbname;charset=utf8",USERNAME,PASSWORD); $db->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); $db->setAttribute(PDO::ATTR_DEFAULT_FETCH_MODE, PDO::FETCH_ASSOC); $db->setAttribute(PDO::ATTR_EMULATE_PREPARES, false); return $db; } Then the code you need will look similar to this <?php require 'db_connect.php'; $pdo = pdoConnect(); $res = $pdo->query("SELECT history , description FROM boats "); $output = ''; foreach ($res as $row) { $output .= "<span>History</span><br> {$row['history']}<br> <span>{$row['description']}</span><br> <br> "; } ?> <html> <body> <?= $output ?> </body> </html>
-
decode and use print_r(). Then follow the keys. echo $data->quoteSummary->result[0]->price->regularMarketPrice->raw;
-
why-My-Data-was-not-uploaded-in-the-Mysql-database(Connection.php)
Barand replied to AKASH2001's topic in PHP Coding Help
An interesting concept though. An input form pointed at a DB connection, at which point the DBAI interface takes over, processes the data, and updates the required tables for you. (MySQL v9.0 perhaps?) -
why-My-Data-was-not-uploaded-in-the-Mysql-database(Connection.php)
Barand replied to AKASH2001's topic in PHP Coding Help
What we don't see are check to see if data was posted to the page data validation an insert query to write the posted data to the database (When posting code in these forums, use the code button "<>" in the toolbar.) -
There is a difference between not knowing how to do something and knowing how to do it (in this case, find a section of a known site) but being too idle to do it yourself.
-
Why not? You are asking us to do everything else for you. You sit back and ask us to do all your legwork.
-
I'm sure he'd rather you read it to him like a bedtime story.
-
Mini php search engine, order with the search term
Barand replied to oz11's topic in PHP Coding Help
SELECT ... ORDER BY LOCATE('google', title) = 0 EG mysql> select * from test; +----------+ | title | +----------+ | Google | | Fox | | CNN | | BBC | | Google 2 | +----------+ 5 rows in set (0.00 sec) mysql> select * from test order by locate('google', title) = 0, title; +----------+ | title | +----------+ | Google | | Google 2 | | BBC | | CNN | | Fox | +----------+ 5 rows in set (0.02 sec) -
Try $futureDate = new DateTime('dec 25'); $now = new DateTime('today'); if ($now > $futureDate) { $futureDate->modify('+1 year'); } echo $now->diff($futureDate)->days;
-
Have you changed the browser?
-
Put them in an array, $var = [ "hello", "good bye", "back soon"]; for ($x=0; $x<3; $x++) { echo $var[$x] . '<br>'; } or $var0 = "hello"; $var1 = "good bye"; $var2 = "back soon"; test($var0, $var1, $var2); function test(...$vars) { for ($x=0; $x<3; $x++) { echo $vars[$x] . '<br>'; } }
-
You need a datetime object when using diff(), you are using you start time string. Re-read my example $event_date = new DateTime($row['evt_start']); $now = new DateTime(); $time_left = $event_date->diff($now)->format('%m months %d days %h hours %i minutes'); What were you expecting with lines like these? ... ( https://www.php.net/manual/en/function.date.php ) $month=date('m',$difference); $days=date('d',$difference);
-
Not sure which block of code we should be looking at, but you do seem to be making heavy weather of calculating date differences $event_date = new DateTime('2022-05-15 15:00:00'); $now = new DateTime(); echo $event_date->diff($now)->format('%m months %d days %h hours %i minutes'); // 3 months 24 days 22 hours 34 minutes
-
The same way that you are doing now. Did you read the code that you posted? foreach ($res as $row) { echo "<li>$row->cat_name ($row->total)</li>\n"; ^^^^^^^^^^^^^^ ^^^^^^^^^^^ cat_name total }