开发者

Variable in SQL Query Not Working?

开发者 https://www.devze.com 2023-02-25 00:38 出处:网络
if (isset($_SESSION[\'user_tz\'])) { $posted = \"CONVERT_TZ(p.posted_on, \'UTC\', \'{$_SESSION[\'user_tz\']}\')\";
    if (isset($_SESSION['user_tz'])) {
        $posted = "CONVERT_TZ(p.posted_on, 'UTC', '{$_SESSION['user_tz']}')";
    } else {
        $posted = 'p.posted_on';
    }

    // Run the query:
    $q = "SE开发者_如何学CLECT t.subject, p.message, username, DATE_FORMAT($posted, '%e-%b-%y %l:%i %p') AS posted FROM threads AS t LEFT JOIN posts AS p USING (thread_id) INNER JOIN users AS u ON p.user_id = u.user_id WHERE t.thread_id = $tid ORDER BY p.posted_on ASC";

I changed the $posted in the query to a plain "posted_on" which returned the time, I also tried some wrapping it in '' and "" but those ended up breaking it entirely; for future reference I'd like to know why that variable isn't getting passed through to the query. It's probably something really simple and I'll feel silly but help would be appreciated greatly.

Thanks.


NULL is a valid value for isset() to trigger TRUE. Use unset($_SESSION['user_tz']);


It seems to me that the way you have it written, it is using $posted as the value to pass to the date_format. What you really want is the contents of $posted so you need to close quotes around it and concatenate the value into the $q string.

0

精彩评论

暂无评论...
验证码 换一张
取 消