Joomla sql 查询不起作用
有人可以告诉我这有什么问题吗?当那里有东西时,它会显示为空,字段中的名称都是正确的:
if($token = JRequest::getVar('token')){
$getImgQuery = 'SELECT adimage FROM #__chronoforms_data_adsList WHERE cf_uid = ' . $token;
$db->setQuery( $getImgQuery );
$imagename = $db->loadResult();
echo $imagename;
$fullimgpath = "adimages/" . $imagename;
}
我在一篇文章中使用它,就在它下面,我有一些更多的代码可以工作:
$query = 'SELECT * FROM #__chronoforms_data_adsList WHERE cf_user_id = ' . $userid;
$db->setQuery( $query );
$result = $db->loadObjectList();
foreach ($result as $x){
//loop through everything including adimage
}
我已经尝试了几个小时来弄清楚它但我似乎无法让它发挥作用,这让我发疯。
can someone tell me what is wrong with this? It comes up empty when there is something there, the names in the fields are all correct:
if($token = JRequest::getVar('token')){
$getImgQuery = 'SELECT adimage FROM #__chronoforms_data_adsList WHERE cf_uid = ' . $token;
$db->setQuery( $getImgQuery );
$imagename = $db->loadResult();
echo $imagename;
$fullimgpath = "adimages/" . $imagename;
}
I'm using this in an article, just below it I have some more code that works:
$query = 'SELECT * FROM #__chronoforms_data_adsList WHERE cf_user_id = ' . $userid;
$db->setQuery( $query );
$result = $db->loadObjectList();
foreach ($result as $x){
//loop through everything including adimage
}
I've been trying to figure it out for hours but I can't seem to get it to work, it's driving me nutz.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我能想到的唯一原因是您的查询根本没有任何行...您是否尝试将其打印出来并在 phpmyadmin 中运行它以验证它是否返回某些内容并且您的 SQL 查询中没有错误你正在发送?
The only reason i can think of is that your query evaluates to no rows at all... Have you tried printing it out and running it out in phpmyadmin to validate that it DOES return something and that there is no errors in your SQL query that you are sending?
假设您想将 $token 设置为 getVar 返回的变量(并且 $token 不包含您想要与
==
进行比较的现有值),那么我会看看另一个getVar 获取的参数 并检查它返回什么您期望例如指定 $hash 并返回 $type。为了调试查询,我会在 loadResult() 之后添加此行。
在输出中,查找任何错误消息并手动运行翻译后的 _sql 查询以检查查询是否按预期工作。
Assuming you want to set $token to the variable returned by getVar (and $token doesn't contain an existing value that you want to compare with
==
), then I'd take a look the other parameters taken by getVar and check it's returning what you're expecting e.g. specify $hash and return $type.To debug the query I'd add this line after loadResult()
In the output, look for any error messages and run the translated _sql query manually to check the query works as expected.