gpt4 book ai didi

php - 如果两个不同表的数据匹配,如何显示具体内容?

转载 作者:行者123 更新时间:2023-11-29 21:15:10 24 4
gpt4 key购买 nike

我在显示用户订单信息时遇到问题。我正在使用 WordPress,所以我必须使用它们的功能。有一个名为 forms 的表,其中包含我想要显示的所有订单信息,另一个名为 wp_users 的表,其中包含电子邮件和用户名。该电子邮件将与表单中的电子邮件相同,因此我正在考虑以某种方式尝试查看表单的电子邮件和 wp_users 的电子邮件是否匹配,这样我就可以向该特定用户显示他的订单信息,但我不知道如何我会这样做。

这就是我获取订单和电子邮件信息的方式

$inputs = $wpdb->get_row("SELECT * FROM form WHERE md5(concat(ID)) =  '$validate'");
if (empty($_REQUEST) || !empty($_GET['order_nr'])) {


?>
<form name="abonnement" action="/" method="post">
1 jaar abonnement: <input type = "radio" name="option" value = "1" checked = "checked"><br>
Eerst volgende nummer: <input type = "radio" name="option" value = "2"><br>
Historische nummer <input type = "radio" name="option" value = "3">
<br><br>
Naam:<input type = "text" name="naam" value = "<?php echo $inputs->naam; ?>" required><br>

Adres:<input type = "text" name="adres" value= "<?php echo $inputs->adres; ?>" required><br>
Postcode/Woonplaats:<input type="text" name = "plaats" value = "<?php echo $inputs->plaats; ?>" required><br>
Land:<input type= "text" name="land" value = "<?php echo $inputs->land; ?>"required><br>
Telefoon: <input type = "text" name="tel" value = "<?php echo $inputs->telefoon; ?>"required><br>
Email: <input type = "email" name="email" value = "<?php echo $inputs->email; ?>" required><br>
Datum: <input type = "text" name="datum" value = "<?php echo $inputs->datum; ?>" required><br><br>
<input type = "hidden" name="order_id" value = "<?php echo $inputs->ID; ?>">

<input id = "appear" type = "checkbox" name ="cadeau"> Geeft u het abonnement cadeau? Vul dan ook het onderstaande formulier in.<br>
<div id="cadeau">

Naam:<input type = "text" name = "cadNaam">
Adres:<input type = "text" name = "cadAdres">
Postcode/Woonplaats:<input type = "text" name = "cadPlaats">
Land:<input type= "text" name = "cadLand">
Telefoon: <input type = "text" name = "cadTel" >
Email: <input type = "text" name = "cadEmail"><br>
</div>

<input type = "submit" name = "formSubmit" value = "Verzenden"><br><br>
</form>


<?php
$wpdb->insert( 'form', array(
'naam' => $_POST['naam'],
'adres' => $_POST['adres'],
'plaats' => $_POST['plaats'],
'land' => $_POST['land'],
'telefoon' => $_POST['tel'],
'email' => $_POST['email'],
'datum' => $_POST['datum'],
'cadNaam' => $_POST['cadNaam'],
'cadAdres' => $_POST['cadAdres'],
'cadPlaats' => $_POST['cadPlaats'],
'cadLand' => $_POST['cadLand'],
'cadTelefoon' => $_POST['cadTel'],
'cadEmail' => $_POST['cadEmail'],
'option' => $option,
'prijs' => $priceDB,
'Tijd' => $now

));

这是我创建 WordPress 用户的地方

$email = $_POST['email'];
$option = $_POST['option'];
$price = "";

if( null == username_exists( $email ) ) {
$password = wp_generate_password( 12, false );
$user_id = wp_create_user( $email, $password, $email );

wp_update_user(
array(
'ID' => $user_id,
'nickname' => $email
)
);


$user = new WP_User( $user_id );
$user->set_role( 'contributor' );

wp_mail( $email, 'Welcome!', 'Your Password: ' . $password );
}

所以它可能必须看起来像这样?

$orderinfo = $wpdb->get_row("SELECT * FROM form WHERE wp_users.email =       form.email");

提前致谢。

最佳答案

使用此查询来检索相同电子邮件值的数据。

 $orderinfo = $wpdb->get_row("SELECT * FROM wp_user inner join form on wp_users.email = form.email");

如果需要,请检查 wp_user 和表单中的用户 ID。

$orderinfo = $wpdb->get_row("SELECT * FROM wp_user inner join form on wp_users.email = form.email and wp_user.user_id= form.user_id");

关于php - 如果两个不同表的数据匹配,如何显示具体内容?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36006618/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com