我已經將$_SESSION
數組的一些值添加到12,121,41
這種格式中。在這裏我對exampe數據庫:構建查詢mysql的問題mysql
|id|title|source
|1 |asda | 12
|2 |sadas| 121
,我需要建立查詢檢索從該表數據,其中包含源從我的$ _SESSION數組中的值。 這裏var_dump是我的$ _SESSION var。
string(30) "12,121,41"
有些建議嗎? 對不起,我的英語,夥計。
我已經將$_SESSION
數組的一些值添加到12,121,41
這種格式中。在這裏我對exampe數據庫:構建查詢mysql的問題mysql
|id|title|source
|1 |asda | 12
|2 |sadas| 121
,我需要建立查詢檢索從該表數據,其中包含源從我的$ _SESSION數組中的值。 這裏var_dump是我的$ _SESSION var。
string(30) "12,121,41"
有些建議嗎? 對不起,我的英語,夥計。
$sessionValues = $_SESSION['source'];
$query = "SELECT * FROM `table_name` WHERE source IN ({$sessionValues})"
連接到數據庫並執行查詢,如下:
$in = $_SESSION['source'];
$sql = "SELECT * FROM my_table WHERE source IN ($in)";
$stm = $db->prepare($sql);
$stm->execute($in_array);
$data = $stm->fetchAll();
構建查詢類似。
$query="select * from table where source in(".$_SESSION.")";
$result = mysqli_query($con,$query);
對於所有會話數據與數據庫中的字段
$keyword = strreplace(",","','",$_SESSION);
$query="select * from table where id in('$keyword')";
$result = mysqli_query($con,$query);
用於特定會話數據
$keyword = $_SESSION;
$query="select * from table where id =."$keyword[0]."; // as per your need you can change array key
$result = mysqli_query($con,$query);
否,會話陣列具有自動生成的值進行匹配。我需要用一個查詢檢索數據,而不是手動。 – ATIKON