Jump to content

Recommended Posts

hello -

 

trying to get a link to pass the value to another page from a mysql query in php hyper link.

 

most of my site is with sessions.

Can we create an array of sessions? session[0], session[1]? because each id would need to have a session id.

 

final outcome:

// session variables for links
$result = mysql_result($query,0,'Id');
$_SESSION['Id']=$result;
  
$sesId=$_SESSION['Id'];
  
<td><a href="url.php"><?php echo $sesId['Id']; ?></a></td>

thanks in advance for your help.

 

theo werntz ii

Link to comment
https://forums.phpfreaks.com/topic/178491-session-arrays/
Share on other sites

I'll show you an example with regular arrays, and you can adapt that to your code.

 

//lets we we have 3 different values we want to add to our array
$val1, $val2, $val3

//now to add them to the array we simply do
$array[] = $val1;
$array[] = $val2;
$array[] = $val3;

//now lets say val val2 and val3 are arrays. we can still do the above.
$val1 = array("one", "two", "three");

$array[] = $val1;

//to access the first element in val1, we can do
echo $array[0][0];//echos "one"

 

There is a pretty good array tutorial in my sig if your interested

Link to comment
https://forums.phpfreaks.com/topic/178491-session-arrays/#findComment-941385
Share on other sites

thanks for the repsonse looking at the link.

 

what i dont get is that your using array with assign variables.

 

my arrays are dynamic; coming from mysql query

 

my array = mysql_result($query,0,'Id')

 

how should i assign that to the array, i've tried using something like that but it pulls one id into the session variable.

 

Link to comment
https://forums.phpfreaks.com/topic/178491-session-arrays/#findComment-941392
Share on other sites

hello -

 

im still having a problem. this array will set but only shows one record from the array. when there are 3 demo data sets.

 

thanks in advance for your help.

 

i want to store the variable id in an array and access that array through session id hyper link on the same page. so that when that hyper link is clicked the session id is passed to the next page.

 

 

here is the page code:

<?php
if (!isset($_SESSION)) {
  session_start();
}
?>
<?php require_once('conn.php'); ?>
<?php
if (!function_exists("GetSQLValueString")) {
function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "") 
{
  if (PHP_VERSION < 6) {
    $theValue = get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue;
  }

  $theValue = function_exists("mysql_real_escape_string") ? mysql_real_escape_string($theValue) : mysql_escape_string($theValue);

  switch ($theType) {
    case "text":
      $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
      break;    
    case "long":
    case "int":
      $theValue = ($theValue != "") ? intval($theValue) : "NULL";
      break;
    case "double":
      $theValue = ($theValue != "") ? doubleval($theValue) : "NULL";
      break;
    case "date":
      $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
      break;
    case "defined":
      $theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue;
      break;
  }
  return $theValue;
}
}


$Id = $_SESSION['Id']; //get users id to pass to record
$Name = $_SESSION['name']; // display users name
$Group = $_SESSION['Group']; // access control group for moderators, members, users

$maxRows_List = 10;
$pageNum_List = 0;
if (isset($_GET['pageNum_List'])) {
  $pageNum_List = $_GET['pageNum_List'];
}
$startRow_List = $pageNum_List * $maxRows_List;

mysql_select_db($database_List, $List);
$query_List = "SELECT * WHERE b.UId1='$UserId'";
$query_limit_List = sprintf("%s LIMIT %d, %d", $query_List, $startRow_List, $maxRows_List);
$List = mysql_query($query_limit_List, $List) or die(mysql_error());
$row_List = mysql_fetch_assoc($List);

$List_Array = array();

while ($row = mysql_fetch_array($List))
{

foreach($row['Id'] as $i=>$val)

$List_Array = $val;

//return $List_Array;
$_SESSION['Id'] = $List_Array;

$myList_Array = $_SESSION['Id'];
}


if (isset($_GET['totalRows_List'])) {
  $totalRows_List = $_GET['totalRows_List'];
} else {
  $all_List = mysql_query($query_List);
  $totalRows_List = mysql_num_rows($all_List);
}
$totalPages_List = ceil($totalRows_List/$maxRows_List)-1;

?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
<style type="text/css"> 
<!-- 
body  {
font: 100% Verdana, Arial, Helvetica, sans-serif;
background: #666666;
margin: 0; /* it's good practice to zero the margin and padding of the body element to account for differing browser defaults */
padding: 0;
text-align: center; /* this centers the container in IE 5* browsers. The text is then set to the left aligned default in the #container selector */
color: #000000;
background-color: #0E03D6;
}
.thrColLiqHdr #container { 
width: 80%;  /* this will create a container 80% of the browser width */
background: #FFFFFF;
margin: 0 auto; /* the auto margins (in conjunction with a width) center the page */
border: 1px solid #000000;
text-align: left; /* this overrides the text-align: center on the body element. */
} 
.thrColLiqHdr #header { 
background: #FFFFFF; 
padding: 0 10px;  /* this padding matches the left alignment of the elements in the divs that appear beneath it. If an image is used in the #header instead of text, you may want to remove the padding. */
} 
.thrColLiqHdr #header h1 {
margin: 0; /* zeroing the margin of the last element in the #header div will avoid margin collapse - an unexplainable space between divs. If the div has a border around it, this is not necessary as that also avoids the margin collapse */
padding: 10px 0; /* using padding instead of margin will allow you to keep the element away from the edges of the div */
}

/* Tips for sidebars:
1. Since we are working in percentages, it's best not to use side padding on the sidebars. It will be added to the width for standards compliant browsers creating an unknown actual width. 
2. Space between the side of the div and the elements within it can be created by placing a left and right margin on those elements as seen in the ".thrColLiqHdr #sidebar1 p" rule.
3. Since Explorer calculates widths after the parent element is rendered, you may occasionally run into unexplained bugs with percentage-based columns. If you need more predictable results, you may choose to change to pixel sized columns.
*/
.thrColLiqHdr #sidebar1 {
float: left; /* this element must precede in the source order any element you would like it be positioned next to */
width: 22%; /* since this element is floated, a width must be given */
background: #FFFFFF; /* the background color will be displayed for the length of the content in the column, but no further */
padding: 15px 0; /* top and bottom padding create visual space within this div  */
}
.thrColLiqHdr #sidebar2 {
float: right; /* this element must precede in the source order any element you would like it be positioned next to */
width: 23%; /* since this element is floated, a width must be given */
background: #FFFFFF; /* the background color will be displayed for the length of the content in the column, but no further */
padding: 15px 0; /* top and bottom padding create visual space within this div */
}
.thrColLiqHdr #sidebar1 p, .thrColLiqHdr #sidebar1 h3, .thrColLiqHdr #sidebar2 p, .thrColLiqHdr #sidebar2 h3 {
margin-left: 10px; /* the left and right margin should be given to every element that will be placed in the side columns */
margin-right: 10px;
}

/* Tips for mainContent:
1. the space between the mainContent and sidebars is created with the left and right margins on the mainContent div.
2. to avoid float drop at a supported minimum 800 x 600 resolution, elements within the mainContent div should be 300px or smaller (this includes images).
3. in the Internet Explorer Conditional Comment below, the zoom property is used to give the mainContent "hasLayout." This avoids several IE-specific bugs.
*/
.thrColLiqHdr #mainContent { 
margin: 0 24% 0 23.5%; /* the right and left margins on this div element creates the two outer columns on the sides of the page. No matter how much content the sidebar divs contain, the column space will remain. You can remove this margin if you want the #mainContent div's text to fill the sidebar spaces when the content in each sidebar ends. */
}

.thrColLiqHdr #footer { 
padding: 0 10px; /* this padding matches the left alignment of the elements in the divs that appear above it. */
background:#FFFFFF;
} 
.thrColLiqHdr #footer p {
margin: 0; /* zeroing the margins of the first element in the footer will avoid the possibility of margin collapse - a space between divs */
padding: 10px 0; /* padding on this element will create space, just as the the margin would have, without the margin collapse issue */
}

/* Miscellaneous classes for reuse */
.fltrt { /* this class can be used to float an element right in your page. The floated element must precede the element it should be next to on the page. */
float: right;
margin-left: 8px;
}
.fltlft { /* this class can be used to float an element left in your page The floated element must precede the element it should be next to on the page. */
float: left;
margin-right: 8px;
}
.clearfloat { /* this class should be placed on a div or break element and should be the final element before the close of a container that should fully contain its child floats */
clear:both;
    height:0;
    font-size: 1px;
    line-height: 0px;
}
#apDiv1 {
position:absolute;
left:206px;
top:83px;
width:151px;
height:34px;
z-index:1;
}
#apDiv2 {
position:absolute;
left:363px;
top:84px;
width:519px;
height:37px;
z-index:2;
}
--> 
</style><!--[if IE]>
<style type="text/css"> 
/* place css fixes for all versions of IE in this conditional comment */
.thrColLiqHdr #sidebar2, .thrColLiqHdr #sidebar1 { padding-top: 30px; }
.thrColLiqHdr #mainContent { zoom: 1; padding-top: 15px; }
/* the above proprietary zoom property gives IE the hasLayout it needs to avoid several bugs */
</style>
<![endif]-->
<script src="SpryAssets/SpryMenuBar.js" type="text/javascript"></script>
<link href="SpryAssets/SpryMenuBarHorizontal.css" rel="stylesheet" type="text/css" />
</head>

<body class="thrColLiqHdr">

<div id="container">
<div id="header">
    <h1> </h1>
    <p> </p>
    <p> </p>
  <!-- end #header --></div>
  <div id="sidebar1">
  <h3> 	</h3>
  <!-- show users ratings overall and per list -->
  <!-- end #sidebar1 --></div>
  <div id="sidebar2">
    <h3> </h3>
  <!-- display current viewers of user list in space and show count of number of views -->
  
  <!-- end #sidebar2 --></div>
  <div id="mainContent">
    <h1> </h1>
    <blockquote>
      <table border="1" cellpadding="1" cellspacing="1">
        <tr></tr>
        <caption align="center">
          List  Click to Edit
        </caption>
        <?php do { ?>
        <tr>
          <td><a href="list.php"><?php echo $myList_Array['Id']; ?></a></td> <-- this is the column that i want to have access the session id -->
          <td><?php echo $row_List['Subject'];?></td>
          <td><?php echo $row_List['Date']; ?></td>
        </tr>
        <?php } while($row_List = mysql_fetch_assoc($List));
	?>
      </table>
      <h2> </h2>
      <p> </p>
    </blockquote>
<!-- end #mainContent --></div>
<!-- This clearing element should immediately follow the #mainContent div in order to force the #container div to contain all child floats --><br class="clearfloat" />
  <div id="footer">
    <p>Footer</p>
  <!-- end #footer --></div>
<!-- end #container --></div>
</body>
</html>
<?php
mysql_free_result($List);
?>

Link to comment
https://forums.phpfreaks.com/topic/178491-session-arrays/#findComment-942180
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.