gpt4 book ai didi

PHP/MYSQL - 如何将从数据库中获取的数据(存储在变量中)分配给 session 变量?

转载 作者:行者123 更新时间:2023-11-29 01:27:38 25 4
gpt4 key购买 nike

我在传递从数据库中获取并存储在变量中的数组变量并将它们传递到 session 变量以在整个站点中使用时遇到了一些问题。

代码:

$rid=$_SESSION['SESS_MEMBER_ID'] ;

$recquery = 'SELECT * FROM clinic_receptionist,clinic_table where clinic_receptionist.recep_clinic_id = clinic_table.ID AND recep_id ='.$rid;

$recresult = mysqli_query($conn,$recquery);

if(mysqli_num_rows($recresult)>0)
{
while($row = mysqli_fetch_assoc($recresult))
{
$cid = $row['clinic_id'];
$cname = $row['clinic_name'];
$name = $row['recep_full_name'];
$phone = $row['recep_mobile'];
$email = $row['recep_email'];
$address = $row['recep_address'];
$gender = explode(",",$row['recep_gender']);
$dob = $row['recep_dob'];
$doj = $row['recep_doj'];
}
}
?>

上面的代码是选择查询发生的地方。我想知道如何将 $cid$cname 分配给不同页面中的 $_SESSION 变量。任何帮助将非常感激。谢谢

代码:

<?php session_start();
include('header.php');

include('menu.php');
include('config.php');

$appquery = 'SELECT * FROM appointment_table,clinic_table where clinic_table.ID = appointment_table.clinic_id';
$appresult = mysqli_query($conn,$appquery);
if(mysqli_num_rows($appresult)>0)
{
while($row = mysqli_fetch_array($appresult))
{
$_SESSION['cid'] = $row['ID'];
$_SESSION['cname'] = $row['clinic_name'];
$ptdate = $row['date'];
$pttime = $row['time'];
$ptname = $row['pt_name'];
$ptphone = $row['pt_ph_num'];
$ptemail = $row['pt_email_id'];

}
}
?>

上面的代码是我想要接收 id 和诊所名称的地方。

最佳答案

<?php
// Start the session
session_start();

//Assigning the values to $_SESSION
$_SESSION['cid'] = $row['clinic_id'];

$_SESSION['cname'] = $row['clinic_name'];;
?>

session_start

关于PHP/MYSQL - 如何将从数据库中获取的数据(存储在变量中)分配给 session 变量?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34216878/

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