News:

Bored?  Looking to kill some time?  Want to chat with other SMF users?  Join us in IRC chat or Discord

Main Menu

1.1B3 SSI.php SQL syntax error..

Started by smsforum, July 20, 2005, 04:42:41 PM

Previous topic - Next topic

smsforum

Folks,
   I've installed 1.1B3 on one of my servers.. all seems fine except one of my SSI.php calls which I use to generate a list of topics from a given board, fail if there are no topics present.

The error reported on screen is:

QuoteYou have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ')
AND hxxp:m.id [nonactive]_MSG = hxxp:t.id [nonactive]_FIRST_MSG
ORDER BY hxxp:t.id [nonactive]_FIRST_MSG DESC
LIMIT 0' at line 6
File: /home/xxxxxx/public_html/smf/SSI.php
Line: 1275

the calling code for the SSI func..

In my given PHP file.. I call my home-made.. list_topics() func..
<?php list_topics("3.0", 10); ?>

.. specifies the board and limit on the number of topics.

then it is defined as..

function list_topics($board, $limit, $start = 0) {
    $cachefile = "/home/xxxxxx/public_html/list_$board.txt";
    $currenttime = time();
    $cachestamp = filemtime($cachefile);

    if ($currenttime - $cachestamp > 60) {
            // open file for writing
            $fh = fopen($cachefile, 'w') or die($php_errormsg);

            // Get topic list
            $my_array = ssi_boardNews($board, $limit, $start, 1, 'array');

            for ($i = 0; $i < sizeof($my_array); $i++) {
                    fwrite($fh, '<a href="');
                    fwrite($fh, $my_array[$i][href]);
                    fwrite($fh, '">');
                    fwrite($fh, $my_array[$i][subject]);
                    fwrite($fh, "</a><br>\n");
            }
            // close file
            fflush($fh);
            fclose($fh);
    }
    include("$cachefile");
}



effectively its a glorified wrapper on the ssi_boardNews() with some caching to file to prevent repetitive calls to the function. I have several of these calls on different boards.. all are working fine except for when the given given board is empty... if I post a topic and repeat the test, all OK

I've disabled the given code for now.. but thought I'd post this as most boards are not likely to be empty and I'd imagine this would go unnoticed.

All in all.. 1.1B3 is looking great and many kudos to the devs.

[Unknown]

It looks like $limit is 0... that won't work with many versions of MySQL.

-[Unknown]

smsforum

LIMIT " . count($posts), __FILE__, __LINE__);

Then the LIMIT statement above from the 2nd SQL query is the cause.. because the post count would be 0 for the empty board..

full code excerpt from SSI.php.. can see how it computes the the post count in the first query and the uses it as the LIMIT directive on the 2nd..

// Find the post ids.
$request = db_query("
SELECT ID_FIRST_MSG
FROM {$db_prefix}topics
WHERE ID_BOARD = $board
ORDER BY ID_FIRST_MSG DESC
LIMIT $start, $limit", __FILE__, __LINE__);
$posts = array();
while ($row = mysql_fetch_assoc($request))
$posts[] = $row['ID_FIRST_MSG'];
mysql_free_result($request);

// Find the posts.
$request = db_query("
SELECT
m.icon, m.subject, m.body, IFNULL(mem.realName, m.posterName) AS posterName, m.posterTime,
t.numReplies, t.ID_TOPIC, m.ID_MEMBER, m.smileysEnabled, m.ID_MSG
FROM {$db_prefix}topics AS t, {$db_prefix}messages AS m
LEFT JOIN {$db_prefix}members AS mem ON (mem.ID_MEMBER = m.ID_MEMBER)
WHERE t.ID_FIRST_MSG IN (" . implode(', ', $posts) . ")
AND m.ID_MSG = t.ID_FIRST_MSG
ORDER BY t.ID_FIRST_MSG DESC
LIMIT " . count($posts), __FILE__, __LINE__);
$return = array();

Advertisement: