Jump to content

SQL syntax error


j634

Recommended Posts

Hi,

 

I am getting this error on my news page of my web site.

 

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 'call from hl_news' at line 1

 

I can't find the error in my code. This is the entire code of my news page.

 

<?

  $q = 'select count(*) as call 
        from 
             hl_news
';
  if (!($sth = mysql_query ($q)))
  {
    print mysql_error ());
    ;
  }

  $row = mysql_fetch_array ($sth);
  $count_all = $row['call'];
  $page = $frm['page'];
  $onpage = 20;
  $colpages = ceil ($count_all / $onpage);
  if ($page <= 1)
  {
    $page = 1;
  }

  if (($colpages < $page AND 1 < $colpages))
  {
    $page = $colpages;
  }

  $from = ($page - 1) * $onpage;
  $q = '' . 'select 
                 *,
                 date_format(date, \'%b-%e-%Y %r\') as d
           from 
                 hl_news 
           where
                 (expiration = 0 || (date + interval expiration day >= current_date))
           order by 
                 date desc
           limit 
                 ' . $from . ', ' . $onpage;
  ($sth = mysql_query ($q) OR print mysql_error ());
  $news = array ();
  while ($row = mysql_fetch_array ($sth))
  {
    if ($row['full_text'] == '')
    {
      $row['full_text'] = $row['small_text'];
    }

    $row['full_text'] = preg_replace ('/
/', '<br>', $row['full_text']);
    array_push ($news, $row);
  }

  $smarty->assign ('news', $news);
  $pages = array ();
  for ($i = 1; $i <= $colpages; ++$i)
  {
    $apage = array ();
    $apage['page'] = $i;
    $apage['current'] = ($i == $page ? 1 : 0);
    array_push ($pages, $apage);
  }

  $smarty->assign ('pages', $pages);
  $smarty->assign ('colpages', $colpages);
  $smarty->assign ('current_page', $page);
  if (1 < $page)
  {
    $smarty->assign ('prev_page', $page - 1);
  }

  if ($page < $colpages)
  {
    $smarty->assign ('next_page', $page + 1);
  }

  $smarty->display ('news.tpl');
?>

 

You can see at: http://www.hyipcharts.com and click on the more news button.

 

Also, could you let me know how the page loads for you. I have to refresh sometimes or get a blank page.

 

Thanks again for the great help,

j634

Link to comment
Share on other sites

Just sourround it with `backticks`.

 

I tried that and still can't get it to work. If I backtick it all I get is a blank page.

 

I tried it like this and worked backwards.

  $q = 'select count(*) as `call` 
        from 
             hl_news
';
  if (!($sth = mysql_query ($q)))
  {
    print mysql_error ());
    ;
  }

  $row = mysql_fetch_array ($sth);
  $count_all = $row[`call`];
  $page = $frm['page'];
  $onpage = 20;

 

I backticked both, saved and tried the page. I get a blank screen. I unbackticked the first call and the page comes, but with the same error.

 

Thanks

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.