从WordPress数据库表中获取特定数据 [英] getting specific data from wordpress database table
问题描述
我正在尝试使用WordPress登录的用户ID,该用户ID应该在表 wp_m_subscription_transaction
中搜索 transaction_user_ID
。
I am trying to use WordPress logged in user id which should search transaction_user_ID
in the table wp_m_subscription_transaction
.
该表具有名为 transaction_user_ID
的列和另一个名为 transaction_paypal_ID
的列
The table has a column called transaction_user_ID
and another called transaction_paypal_ID
.
逻辑:如果用户ID ==交易用户ID,则获取交易贝宝ID
logic:if user id == transaction user id then get transaction paypal id
网址以及用户ID电子邮件地址
并执行网址以获取代码-这是我的最终输出
which should be passed to the url along with the user id email address and the execute the url to get the a code - this is my final output
如何实现?
我正在开发的代码就像这样,显然是不完整的&获取和使用数据库查询的错误
The code which I am developing is like this which is obviously incomplete & error for the getting and using the database query
<?php $user_id = get_current_user_id();
$query = "SELECT * FROM $wpdb->;wp_m_subscription_transaction
if ($user_id ==$query) {
<a href="http://primary.copyminder.com/cm_prodkey.php?DID=********&Password=*****&ProdCode=*******&NumRequired=1&TransNum=(GET THIS FROM DATABASE) &CustEmail=". $current_user->user_email .">Get ur Code</a>
}
else {
echo 'You are not logged in as user ';}?>
推荐答案
首先,由于您还需要电子邮件地址,使用 wp_get_current_user()
获取当前用户的所有详细信息,而不仅仅是ID。
First, since you need the email address as well, get all the current user's details, not just the id, using wp_get_current_user()
.
第二,您的查询是错误;您尚未关闭引号,并且使用了分号。如果我没看错的话,您需要输入以下内容:
Secondly, your query is wrong; you haven't closed the quotes, and have a stray semicolon. If I've read it right, you need something like:
select transaction_paypal_ID
from wp_m_subscription_transaction
where transaction_user_ID = [the user's ID]
如果您在查询中仅获得一个值,则表示可以使用 $ wpdb-> get_var()
If you're only getting a single value in a query, you can retrieve it with $wpdb->get_var()
检索它,如果查询未返回行,这不一定意味着用户未登录。您可以使用 is_user_logged_in()
检查用户是否已登录。
If the query doesn't return a row, it doesn't necessarily mean the user isn't logged in. You can check if a user is logged in using is_user_logged_in()
.
类似的事情应该起作用。我尚未测试,您必须自己构建URL。
Something like this should work. I haven't tested, and you'll have to build up the URL yourself.
<?php
if (is_user_logged_in()) {
$user = wp_get_current_user();
$paypal_id = $wpdb->get_var("select transaction_paypal_ID from wp_m_subscription_transaction where transaction_user_ID = " . (int) $user->ID);
if ($paypal_id) {
// Build up your URL here, with $paypal_id and $user->user_email
}
else {
echo 'No transaction found for the current user';
}
}
else {
echo 'You are not logged in';
}
?>
这篇关于从WordPress数据库表中获取特定数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!