Страница 1 из 1

php странности при 2 запроса

Добавлено: 2009-05-22 20:12:07
ProFTP
рабочее
строка 139

Код: Выделить всё

    // Get all the important topic info.
    $request = db_query("
        SELECT
            t.numReplies, t.numViews, t.locked, ms.subject, t.isSticky, t.ID_POLL,
            t.ID_MEMBER_STARTED, t.ID_FIRST_MSG, t.ID_LAST_MSG,
            " . ($user_info['is_guest'] ? '0' : 'IFNULL(lt.ID_MSG, -1) + 1') . " AS new_from
        FROM ({$db_prefix}topics AS t, {$db_prefix}messages AS ms)" . ($user_info['is_guest'] ? '' : "
            LEFT JOIN {$db_prefix}log_topics AS lt ON (lt.ID_TOPIC = $topic AND lt.ID_MEMBER = $ID_MEMBER)") ."
        WHERE t.ID_TOPIC = $topic
            AND ms.ID_MSG = t.ID_FIRST_MSG
        LIMIT 1", __FILE__, __LINE__);
    if (mysql_num_rows($request) == 0)
        fatal_lang_error(472, false);
    $topicinfo = mysql_fetch_assoc($request);
    mysql_free_result($request);

    // The start isn't a number; it's information about what to do, where to go.

там может $topic быть не определено, переделываю не много движок....


меняю на:
(добавил запрос и переопределил $topic )

Код: Выделить всё

    // Get all the important topic info.
    $request = db_query("
        SELECT
            t.numReplies, t.numViews, t.locked, ms.subject, t.isSticky, t.ID_POLL,
            t.ID_MEMBER_STARTED, t.ID_FIRST_MSG, t.ID_LAST_MSG,
            " . ($user_info['is_guest'] ? '0' : 'IFNULL(lt.ID_MSG, -1) + 1') . " AS new_from
        FROM ({$db_prefix}topics AS t, {$db_prefix}messages AS ms)" . ($user_info['is_guest'] ? '' : "
            LEFT JOIN {$db_prefix}log_topics AS lt ON (lt.ID_TOPIC = $topic AND lt.ID_MEMBER = $ID_MEMBER)") ."
        WHERE t.ID_TOPIC = $topic
            AND ms.ID_MSG = t.ID_FIRST_MSG
        LIMIT 1", __FILE__, __LINE__);
    if (mysql_num_rows($request) == 0)
        // fatal_lang_error(472, false);
    $topicinfo = mysql_fetch_assoc($request);
    mysql_free_result($request);
    
    
                            $request2 = db_query("
            SELECT true_topic
              FROM bad_topic
             WHERE bad_topic = " .$_GET['topic'] ." LIMIT 1 " , __FILE__, __LINE__);
        
        //$user_settings = mysql_fetch_assoc($request2);
        
        
        while ($row = mysql_fetch_assoc($request2))
    {
        $topic2 = $row['true_topic'];

      // echo $row['true_topic'];
    }
    
        if ($topic2) {
         $topic = $topic2;
           }    
    

    // The start isn't a number; it's information about what to do, where to go.


мне выдает ошибку движок

Код: Выделить всё

You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'AS isRead
FROM smf_sdfmessages
WHERE ID_MSG IN (7724)
ORDER BY ID_MSG' at line 4
File: /home/mydm/www/data/Sources/Display.php
Line: 760
Line: 760
ORDER BY ID_MSG" . (empty($options['view_newest_first']) ? '' : ' DESC'), __FILE__, __LINE__);

полностью:

Код: Выделить всё

        if (!empty($posters))
            loadMemberData($posters);
        $messages_request = db_query("
            SELECT
                ID_MSG, icon, subject, posterTime, posterIP, ID_MEMBER, modifiedTime, modifiedName, body,
                smileysEnabled, posterName, posterEmail, k_os, k_br, k_os_ico, k_br_ico, 
                ID_MSG_MODIFIED < $topicinfo[new_from] AS isRead
            FROM {$db_prefix}messages
            WHERE ID_MSG IN (" . implode(',', $messages) . ")
            ORDER BY ID_MSG" . (empty($options['view_newest_first']) ? '' : ' DESC'), __FILE__, __LINE__);

        // Go to the last message if the given time is beyond the time of the last message.
        if (isset($context['start_from']) && $context['start_from'] >= $topicinfo['numReplies'])
            $context['start_from'] = $topicinfo['numReplies'];
куда копать запрос может не правильный? тот который я добавил

Re: php странности при 2 запроса

Добавлено: 2009-05-22 21:21:46
Sla
ID_MSG_MODIFIED < $topicinfo[new_from] AS isRead

что это?

Re: php странности при 2 запроса

Добавлено: 2009-05-22 21:50:07
zg
ProFTP писал(а):куда копать
в глубь. :-o
ProFTP писал(а):запрос может не правильный?
гм.. было бы странно, если бы запрос был правильным и выдавалась ошибка MySQL.

Re: php странности при 2 запроса

Добавлено: 2009-05-22 23:47:18
ProFTP
сделал

Код: Выделить всё

    // Get all the important topic info.
    $request = db_query("
        SELECT
            t.numReplies, t.numViews, t.locked, ms.subject, t.isSticky, t.ID_POLL,
            t.ID_MEMBER_STARTED, t.ID_FIRST_MSG, t.ID_LAST_MSG,
            " . ($user_info['is_guest'] ? '0' : 'IFNULL(lt.ID_MSG, -1) + 1') . " AS new_from
        FROM ({$db_prefix}topics AS t, {$db_prefix}messages AS ms)" . ($user_info['is_guest'] ? '' : "
            LEFT JOIN {$db_prefix}log_topics AS lt ON (lt.ID_TOPIC = $topic AND lt.ID_MEMBER = $ID_MEMBER)") ."
        WHERE t.ID_TOPIC = $topic
            AND ms.ID_MSG = t.ID_FIRST_MSG
        LIMIT 1", __FILE__, __LINE__);
        
     $topicinfo = mysql_fetch_assoc($request);
     mysql_free_result($request);
     
    if (mysql_num_rows($request) == 0) {
    
        $request2 = db_query("
            SELECT true_topic
               FROM bad_topic
             WHERE bad_topic = ".$topic." LIMIT 1 " , __FILE__, __LINE__);
        
        //$user_settings = mysql_fetch_assoc($request2);        
        
        
        while ($row = mysql_fetch_assoc($request2))
    {
        $topic2 = $row['true_topic'];

      // echo $row['true_topic'];
    }
    
    mysql_free_result($request2);
    
        if (isset($topic2)) {
        
        $topic = null;
        
         $topic = $topic2;
         
    $request = null;
    
    $request = db_query("
        SELECT
            t.numReplies, t.numViews, t.locked, ms.subject, t.isSticky, t.ID_POLL,
            t.ID_MEMBER_STARTED, t.ID_FIRST_MSG, t.ID_LAST_MSG,
            " . ($user_info['is_guest'] ? '0' : 'IFNULL(lt.ID_MSG, -1) + 1') . " AS new_from
        FROM ({$db_prefix}topics AS t, {$db_prefix}messages AS ms)" . ($user_info['is_guest'] ? '' : "
            LEFT JOIN {$db_prefix}log_topics AS lt ON (lt.ID_TOPIC = $topic AND lt.ID_MEMBER = $ID_MEMBER)") ."
        WHERE t.ID_TOPIC = $topic
            AND ms.ID_MSG = t.ID_FIRST_MSG
        LIMIT 1", __FILE__, __LINE__);     
       

         $topicinfo = null;
             //  fatal_lang_error(472, false);
     $topicinfo = mysql_fetch_assoc($request);
     mysql_free_result($request);
           
        }             
    } else {
        
         fatal_lang_error(472, false);
        
        }