从表中获取session_user等级

时间:2019-10-05 20:21:47

标签: php mysql session

我有一个数据库,其表名为from datetime import date from datetime import datetime import pandas as pd import sqlite3 import numpy as np from sqlalchemy import create_engine engine = create_engine('sqlite:///C:\\\\\data3.db', echo=False) #create_local table() name = 'Bob' startDate = pd.to_datetime('10/02/2019').date() endDate = pd.to_datetime('10/09/2019').date() d = pd.date_range(start=startDate, end=endDate, freq='D') dd = pd.DataFrame({'Date': d, 'Name':[name]*len(d)}) #print (dd) df1 = pd.DataFrame(dd, columns =['Date']) # PUll data from database dates= {'Date':['2019-10-07','2019-10-06','2019-11-03','2019-11-02','2019-10-09','2019-10-08','2019-10-07','2019-10-06','2019-10-05','2019-10-04','2019-10-03','2019-10-02']} df=pd.DataFrame(dates) df['Date']=df['Date'].astype(str) df['Date']=df['Date'].str.slice(0,10) #create column and count df2 = pd.DataFrame(df, columns = ['Date']) df2= df2.groupby("Date").agg({"Date": np.sum, "Date": pd.Series.count}).rename(columns={'Date': 'count'}) # extract the dates with 2 counts into new dataframe df2=df2.loc[df2['count'] == 2] print (df2) ,列为Usersusername。我想基于sum_score检索会话用户的等级。所以我尝试了类似下面的代码:

sum_score

我要打印<?php session_start(); $db = mysqli_connect('localhost', 'root', '', 'registration'); $rankname= $_SESSION['username']; ?> <body> <?php $selectrank = "SELECT username, FIND_IN_SET(sum_score, (SELECT GROUP_CONCAT( sum_score ORDER BY sum_score DESC ) FROM users )) AS rank FROM users WHERE username = '$rankname'"; $selectuserrank= mysqli_query($db,$selectrank); $ranking= mysqli_fetch_assoc($selectuserrank) ?> Your rank is #<?php echo "$ranking"; ?> 的等级。但是使用上面的代码我得到了错误

  

数组到字符串的转换

session_user

有人可以告诉我如何获得排名。

1 个答案:

答案 0 :(得分:0)

这意味着$ranking是一个数组。首先,通过print_r($ranking)查看此数组。然后选择所需的元素,在您的情况下为rank

所以,写下:  <?php echo $ranking['rank']; ?>

不仅仅是<?php echo $ranking; ?>