Jump to content

mysql syntax error


bheo

Recommended Posts

hey guyss..

can u help me repair my articles.php

me use php and MySQL - 4.1.14-standard

I got ERROR like this :

[quote]MYSQL_ERRORMSG: 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 'AND status='online' ORDER BY rank' at line 1
SQL STMNT: SELECT rank FROM Articles WHERE art_cat_id= AND status='online' ORDER BY rank

Uninitialized object resource[/quote]


this one my articles.php :
[code]
require_once('./php_includes/common.php');
require_once('./php_includes/My_access.php');
require_once('./php_includes/Template.php');
// Global variables
$template        = 'templates/template.html';
$template_main    = 'templates/articles_main.html';
$template_right    = 'templates/articles_right.html';
$current_date    = date("l, d F Y");
$db        = new MyDb($USERNAME, $PASSWD, $DBASE, $HOST);
$status = ($status) ? $status : 'online';
$rank = ($rank) ? $rank : GetRank($db, $art_cat_id, $status);
function GetRank($db, $art_cat_id, $status) {
    $r = $db->Select(    'Articles',
                        'rank',
                        "art_cat_id=$art_cat_id AND status='$status'",
                        'rank'
                    );
    $aRank = $r->Fetch();
    return $aRank[0];
}
$rm = $db->Select('Articles A, ArticleParagraphs P, ArticleCategories C',
                  'A.title,A.sub_title,A.image,A.summary,' .
            'P.title AS par_title,P.body AS par_body,P.image_width AS par_image_width,' .
            'P.image AS par_image,P.image_align AS par_image_align,P.image_caption,C.cat_name',
            "A.article_id=P.article_id AND A.art_cat_id=$art_cat_id AND A.rank=$rank AND A.art_cat_id=C.art_cat_id AND A.approval='Y' AND A.status='$status'",
            'P.par_nr'
                  );
$M    = new Template($template_main);
$block_paragraphs = 'paragraphs';
$M->DefineBlock($block_paragraphs);
$n = 0;
while($aPar = $rm->Fetch()) {
    if ($n == 0) {
        $page_title    = $aPar['cat_name'] . ' :' . $aPar['title'];
        $M->Assign(array(
                'print_link'=>    $print_script . '?rank=' . $rank .
                                '&art_cat_id=' . $art_cat_id .
                                '&url=' . rawurlencode(ereg_replace('&','|',$REQUEST_URI)),
                'category'    =>    $aPar['cat_name'],
                'title'        =>    ($aPar['sub_title']) ? $aPar['title'] .': ' . $aPar['sub_title'] : $aPar['title'],
                'summary'    =>    ($aPar['summary']) ? '<em>' . $aPar['summary'] . '</em>' : '',
            ));
    }
    $aParContent = array(
            'par_title' => ($aPar['par_title']) ? '<h3>' . $aPar['par_title'] . '</h3>' : '',
            'par_body'    => $aPar['par_body']
    );
    if ($aPar['par_image']) {
        if (($aPar['par_image_width']) && ($aPar['par_image_width'] < 440)) {
            $par_image = '<table border="0" align="' . $aPar['par_image_align'] .
                            '" width="' . ($aPar['par_image_width'] + 2) . '">';
        } else {
            $par_image = '<table border="0" width="100%">';
        }
        $par_image .= '<tr><td><img src="' . $images_url . '/' . $aPar['par_image'] .
                            '" border="1"></td></tr>';
        if ($aPar['image_caption']) {
            $par_image .= '<tr><td class="caption">' . $aPar['image_caption'] . '</td></tr>';
        }
       
        $par_image .= '</table>' . "\n";
    }
   
    $M->AssignBlock($block_paragraphs,array(
            'par_image'    => ($par_image) ? $par_image : '',
            'par_title' => ($aPar['par_title']) ? '<h3>' . $aPar['par_title'] . '</h3>' : '',
            'par_body'    => $aPar['par_body']
        ));
       
    unset($par_image);
}
$main_content = $M->Parse(0);
$rr = $db->Select(
                'Articles A, ArticleCategories C',
                'A.article_id,A.title,A.sub_title,A.rank,A.language,C.image',
                "A.art_cat_id=C.art_cat_id AND A.art_cat_id=$art_cat_id AND A.rank<>$rank AND A.approval='Y' AND A.status='online'",
                'rank'
                );
$R    = new Template($template_right);
$block_links = 'links';
$R->DefineBlock($block_links);
$block_articles = 'articles';
$R->DefineBlock($block_articles);
$image = $db->GetField('ArticleCategories','image',"art_cat_id=$art_cat_id");
$R->Assign(array(
        'image'    => ($image) ? $image : 'undefined.gif'
    ));
$archives = CheckArchive($art_cat_id);
$n=0;
while($aLinks = $rr->Fetch()) {
    if ( ($aLinks['title'] == 'FAQ') && ($art_cat_id == 29) ) {
    $R->AssignBlock($block_links,array(
            'link'            => 'faq.php?category_id=1',
            'link_title'    => ($aLinks['sub_title']) ? $aLinks['title'] . ' - ' . $aLinks['sub_title'] : $aLinks['title'],
            'image_index'    => $n,
            'language'        => $aLinks['language']
        ));
    } else {
        $R->AssignBlock($block_links,array(
            'link'            => $PHP_SELF . '?rank=' . $aLinks['rank'] . '&art_cat_id=' . $art_cat_id,
            'link_title'    => ($aLinks['sub_title']) ? $aLinks['title'] . ' - ' . $aLinks['sub_title'] : $aLinks['title'],
            'image_index'    => $n,
            'language'        => $aLinks['language']
        ));
    }
    $n++;
}
if ($n) {
    $R->AssignBlock($block_articles,array(
            'links_header'    => 'Other articles:'
        ));
}
if ($archives) {
    $block_archives = 'archives';
    $R->DefineBlock($block_archives);
    $R->AssignBlock($block_archives,array(
            'art_cat_id'    => $art_cat_id
        ));
} else {
    $block_archives = 'archives';
    $R->DefineBlock($block_archives);
    $R->DeleteBlock($block_archives);
}
$right_content = $R->Parse(0);
               
$T    = new Template($template);
$T->Assign(array(
            'page_title'    => $PREFIX_PAGE_TITLE . ' - ' . $page_title,
            'date'            => $current_date,
            'main_content'    => $main_content,
            'right_content'    => $right_content
    ));
$T->Parse();
[/code]

sample error :

[url=http://85.17.41.220/~indonesia/articles.php?rank=2&art_cat_id=5]http://85.17.41.220/~indonesia/articles.php?rank=2&art_cat_id=5[/url]


thanks for help

regard
Link to comment
Share on other sites

[code]$db        = new MyDb($USERNAME, $PASSWD, $DBASE, $HOST);
$status = ($status) ? $status : 'online';
$rank = ($rank) ? $rank : GetRank($db, $art_cat_id, $status);
function GetRank($db, $art_cat_id, $status) {
    $r = $db->Select(    'Articles',
                        'rank',
                        "art_cat_id=$art_cat_id AND status='$status'",
                        'rank'
                    );
    $aRank = $r->Fetch();
    return $aRank[0];
}
[/code]
that way nothing after art_cat_id couse we are already to to definitie above

i was only wonder with tag  ' or  ""
Link to comment
Share on other sites

[quote author=bheo link=topic=114258.msg464905#msg464905 date=1163001482]
[code]$db        = new MyDb($USERNAME, $PASSWD, $DBASE, $HOST);
$status = ($status) ? $status : 'online';
$rank = ($rank) ? $rank : GetRank($db, $art_cat_id, $status);
function GetRank($db, $art_cat_id, $status) {
    $r = $db->Select(    'Articles',
                        'rank',
                        "art_cat_id='$art_cat_id' AND status='$status'",
                        'rank'
                    );
    $aRank = $r->Fetch();
    return $aRank[0];
}
[/code]
that way nothing after art_cat_id couse we are already to to definitie above

i was only wonder with tag  ' or  ""

[/quote]
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.