Drupal 和PHP/MySQL:如何将字段与当前用户的字段进行比较?
我有一个问题,与 drupal 中的 php 语法/mysql 有关:
假设 userA 创建了一个名为“test”的内容类型,他在字段 field_example
中填充了值“xxx”。随后,另一个用户 userB 创建了另一个内容,并使用相同的值“xxx”填充相同的字段 field_example
。
我想知道如何仅使用创建的节点(其中字段 field_example
与当前用户相同)显示视图?我正在使用的内容类型“测试”中没有(并且我不想)用户引用。
我已经查看了 View PHP Filter,但我想知道如何比较字段的值?这是我的尝试 [我不是 PHP 专家,您可能会注意到:)]:
<?php
$a="SELECT uid FROM users WHERE uid=%d";
/* ??? How to create $b which can get value of field_example from content_type_test from current user which is logged in ? */
$b="";
$c="SELECT field_example FROM content_type_test";
if ($b==$c){
echo "Ok, I've what I want :) ";
}
?>
任何帮助将不胜感激,因为我已经有一段时间在寻找有关此查询的信息了...
谢谢大家:)
I've an issue, which is about php syntax/mysql in drupal:
Let's say that userA has created a content type called "test" where he filled the field field_example
with value "xxx". Afterwards, another user, userB has created another content and filled the same field field_example
with the same value "xxx".
I'd like to know how is it possible to display a view only with the node created where the field field_example
is the same for the current user ? I don't have (and i don't want) a user reference in the content type "test" i'm using.
I've looked through View PHP Filter, but i'm wondering how to compare values of field ? Here's my attempt [i'm not an expert in PHP as you'll might notice :) ] :
<?php
$a="SELECT uid FROM users WHERE uid=%d";
/* ??? How to create $b which can get value of field_example from content_type_test from current user which is logged in ? */
$b="";
$c="SELECT field_example FROM content_type_test";
if ($b==$c){
echo "Ok, I've what I want :) ";
}
?>
Any help would be greatly appreciated since it's been a while i'm looking for information about this query...
Thanks all :)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我没有视图模块解决方案。
我想到的一个想法是,如果用户 A 提交多个节点怎么办,那么您会使用哪个示例值?另外,您使用的 Drupal 版本是什么?
假设用户只会提交这种类型的一种内容,并且您正在运行 Drupal 6(我从代码示例中猜测),那么它可能看起来像这样:
如果用户提交多个这些内容类型,那么就会有这是避免在这里写小说的另一个答案。有几种方法可以解决这个问题。
另外,如果这是 Drupal 7,我也会使用不同的函数。
I don't have a Views module solution.
One thought that comes to mind is what if User A submits multiple nodes, which example value would you use then? Also, what version of Drupal are you working with?
Assuming that a user will only ever submit one content of this type and you are running Drupal 6 (my guess from code examples), then it might look something like this:
If users submit more than one of those content types, then that would have to be another answer to avoid from writing a novel here. There's a couple ways to approach that.
Also if this was Drupal 7, I'd be using different functions as well.
我假设你想要这样的东西:
I assume you want something like this: