Jump to content

Barand

Moderators
  • Posts

    24,563
  • Joined

  • Last visited

  • Days Won

    822

Everything posted by Barand

  1. Define $WINNERS = []; before your query. Then if there are no query results the in_array() is still valid.
  2. Thank you for sharing that. Is there a question to go with it? Please use code button <> when posting code.
  3. Your problem is was where to use backticks and where to use single quotes.
  4. The query you ran in PHPMyAdmin appears to be the only one above that has correct syntax.
  5. Could be one of those really useful functions that comes free with a framework eg function get_field($key) { return $_GET[$key]; }
  6. Yes it is $a = ''; $b = 2; echo $a + $b; with version 8, gives
  7. Sounds like one or more of those get_fields is an empty string.
  8. Apart from unnecessary field retrieval and loops, what is the nature of your problem?
  9. 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>
  10. decode and use print_r(). Then follow the keys. echo $data->quoteSummary->result[0]->price->regularMarketPrice->raw;
  11. 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?)
  12. 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.)
  13. 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.
  14. Why not? You are asking us to do everything else for you. You sit back and ask us to do all your legwork.
  15. I'm sure he'd rather you read it to him like a bedtime story.
  16. 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)
  17. Try $futureDate = new DateTime('dec 25'); $now = new DateTime('today'); if ($now > $futureDate) { $futureDate->modify('+1 year'); } echo $now->diff($futureDate)->days;
  18. Have you changed the browser?
  19. 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>'; } }
  20. What needs to be H and Y? The datetimes already are.
  21. 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);
  22. 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
  23. 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 }
  24. If you want what your topic title stated it would be SELECT ..... FROM request WHERE request_date + INTERVAL 24 HOUR <= NOW()
×
×
  • 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.