2

我是聪明的“菜鸟”。我需要在我的 .tpl 文件之一中执行以下代码:

  <? // SELECT sql query
$sql = "SELECT 'id' , 'title' FROM `forum_posts` WHERE bid = '1' ORDER BY 'date' DESC LIMIT 4"; 

// perform the query and store the result
$result = query($sql);

// if the $result contains at least one row
if ($result->num_rows > 0) {
  // output data of each row from $result
  while($row = $result->fetch_assoc()) {
    echo '<tr>
        <td><a href="http://www.site.com/forum.php?topic='. $row['id']. '">'. $row['title']. '</a>  </td>  
        </tr>   ';
  }
}
else {
  echo 'No news';
}
?>

我已经尝试了 3 个小时,在网上冲浪,但没有成功。请帮忙!

4

2 回答 2

1

您使用引号而不是反引号作为列名,只需更改它们以避免错误

SELECT `id` , `title` FROM `forum_posts` WHERE `bid` = '1' ORDER BY `date` DESC LIMIT 4"; 
于 2013-05-30T15:51:46.340 回答
0

要求('../libs/SmartySQL.class.php');

$smarty = new SmartySQL( array('pdo_dsn' => 'mysql:dbname=db_name;host=localhost', 'pdo_username' => 'username', 'pdo_password' => 'password', 'pdo_driver_options' => array( ) ) );

$smarty->display('index.tpl');

于 2014-02-04T11:01:59.647 回答