php - SQL 命令的类型强制转换警告

标签 php html sql postgresql types

我已经坚持了一段时间了,我知道这是一个非常初学者,但找不到任何类似的问题。

我正在尝试显示我最后一个主题的详细信息,但我收到了警告。

*Warning: pg_exec() [<a href='function.pg-exec'>function.pg-exec</a>]:
Query failed: 
ERROR: operator does not exist: character varying = integer LINE 4: WHERE
t_cat = 3 ^
HINT: No operator matches the given name and argument type(s). You
might need to add explicit type casts.*

感谢任何帮助

$topicsearh = pg_exec($db, 
     "SELECT t_id, t_subject, t_date, t_cat
      WHERE t_cat = " . $row['s_id'] . "
      ORDER BY t_date DESC LIMIT 1"
);      
if(!$topicsearh){
          echo 'Last topic could not be displayed.';
}
else{
      while($trow = pg_fetch_assoc($topicsearh))
      echo '<a href="topicview.php?id=' . $trow['t_id'] . '">' . $trow['t_subject'] .   
          '</a> at ' . date('d-m-Y', strtotime($trow['t_date']));
}

最佳答案

您需要定义FROM 表。

示例

SELECT t_id, t_subject, t_date, t_cat FROM TABLE_NAME WHERE...
                            ----------^^^^^^^^^^^^^^^-----

还有如下所示的 con-cat。

WHERE t_cat = '". $row['s_id'] ."'

关于php - SQL 命令的类型强制转换警告,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15715011/

相关文章:

sql - Hive sql 结构不匹配

php - 乔姆拉 | PHP : Have a category blog listing/latest articles within the menu structure

PHP - 遍历数组并仅在迭代之间发生变化时打印出值

html - 与矢量效果 : non-scaling-stroke 结合使用时,内联 SVG <circle> 在 Firefox 中中断

javascript - 从 rest api 调用数据并解析到 ui 中的表中

mysql - 在mysql中的单个查询中更新两个表

php - .htaccess 删除 index.php 并从 URL 中隐藏参数键

php - 如何在 codeigniter 中使用插入或替换

javascript - jQuery 下拉菜单显示不正确

sql - 加入;请只记录一张!