php - Database Retrieval to Session Variable Storage -


php 7 , mysql. want take set of labels stored in database , individually place each label in own session variable can use them tab labels in application.

i can retrieve data , echo corresponding session variables show not set status.

<?php  require_once('dbconnect.inc.php');  $_session['histopic'] = "dash";  $numnames = 100;  ($i = 1; $i <= $numnames; $i++) {      $stmt = $pdo->prepare('select hislabelsname hislabels hislabelsid = ?');      $temp = $i;      $stmt->execute(array($temp));     $result = $stmt->fetchall();      foreach ($result $row) {         $_session['hislabelsname$i'] = $row["hislabelsname"];     }      echo $_session['hislabelsname$i'] . "<br>";     echo $_session['hislabelsname5'] . "<br>"; } 

echo $_session['hislabelsname5']; produces undefined index error.

how fix this?

tia.

you have use double quotes this:

$_session["hislabelsname$i"] = $row["hislabelsname"]; 

you this:

$_session["historylabelsname][$i] = $row["hislabelsname"]; 

then echo either:

echo $_session["hislabelsname5"] or echo $_session["hislabelsname][5];


Comments

Popular posts from this blog

ubuntu - PHP script to find files of certain extensions in a directory, returns populated array when run in browser, but empty array when run from terminal -

php - How can i create a user dashboard -

javascript - How to detect toggling of the fullscreen-toolbar in jQuery Mobile? -