空格中的附加变量值

时间:2014-04-28 09:59:32

标签: php variables

我试图给我的" get_threads"根据实际情况变量一些额外的内容。但它没有按预期工作,查询根本没有执行。 看起来" final"中有一些空白缺失。变量。 但是当我将它们添加到值时,输出完全消失了。

输出查询是:

SELECT id, main_forum_id, icon_id, title, description, author_id, closed, views, posts, date_created, last_post_author_id, last_replyTime FROM forum_thread WHERE main_forum_id= ('1') ORDER BY views ASC LIMIT 0, 20

这就是代码:

$get_threads  = "SELECT id, main_forum_id, icon_id, title, description, author_id, closed, views, posts, date_created, last_post_author_id, last_replyTime FROM forum_thread WHERE main_forum_id= ('" . $actualBoard . "')";
if (isset($_GET[ 'sortField' ])) {
switch ($_GET[ 'sortField' ]) {
    case topic:
        $get_threads  .= " ORDER BY title ASC ";
        break;

    case rating:
        $get_threads  .= " ORDER BY rating ASC ";
        break;

    case replies:
        $get_threads  .= " ORDER BY replies ASC ";
        break;

    case views:
        $get_threads  .= " ORDER BY views ASC ";
        break;

    case lastReply:
        $get_threads  .= " ORDER BY last_replyTime DESC ";
        break;      
        }
    } else {
$lastReplyClass = 'columnLastPost active';
$get_threads  .= " ORDER BY last_replyTime ASC ";
    }
$get_threads  .= " LIMIT $start, $perPage";

解决方案:

好的,我是个白痴...... 有时间的格式功能并删除它。这导致了错误:

Fatal error: Call to undefined function formatDateString() 

3 个答案:

答案 0 :(得分:2)

SELECT id, main_forum_id, icon_id, title, description, author_id, closed, views, posts, date_created, last_post_author_id, last_replyTime FROM forum_thread WHERE main_forum_id= ('1') ORDER BY last_replyTime ASCLIMIT 20, 20

ASCLIMIT?

必须有一个空间。

您应该在LIMIT之前和ORDER BY之前添加一个空格

$get_threads  .= " ORDER BY last_replyTime ASC";
    }
$get_threads  .= " LIMIT $start, $perPage";

答案 1 :(得分:0)

ORDER BY last_replyTime ASCLIMIT 20 20

之间添加空格

同样switch case被单(')或双("")引号包围。

例如,

case "topic":
 break;
case "views":
 break;

答案 2 :(得分:0)

$get_threads  = "SELECT id, main_forum_id, icon_id, title, description, author_id, closed, views, posts, date_created, last_post_author_id, last_replyTime FROM forum_thread WHERE main_forum_id= ('" . $actualBoard . "') ";
    $sortField = (isset($_GET[ 'sortField' ])) ? $_GET[ 'sortField' ] : '';

    switch ($sortField) {
        case 'topic':
            $get_threads  .= " ORDER BY title ASC ";
            break;

        case 'rating':
            $get_threads  .= " ORDER BY rating ASC ";
            break;

        case 'replies':
            $get_threads  .= " ORDER BY replies ASC ";
            break;

        case 'views':
            $get_threads  .= " ORDER BY views ASC ";
            break;

        case 'lastReply':
            $get_threads  .= " ORDER BY last_replyTime DESC ";
            break;      
        default:{
            $lastReplyClass = 'columnLastPost active';
            $get_threads  .= " ORDER BY last_replyTime ASC ";
            }
            break;      
    }

    $get_threads  .= " LIMIT $start, $perPage";
相关问题