ahref link with dynamic data | Member | | Join Date: Jan 2009 Location: USA
Posts: 118
| |
hello -
trying to get a link to pass the value to another page from a mysql query in php through the url.
or i could use sessions. 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: -
<td><a href="url?parameter">parameter name</a><?php echo $parameter['Id']; ?></td>
-
thanks in advance for your help.
theo werntz ii
|  | Expert | | Join Date: Dec 2007 Location: Moon, Dark Side
Posts: 1,094
| | | re: ahref link with dynamic data
You can put an array into a session by serializing it first and unserializing it later
check out php.net/serialize
url?parameter is not right, you need a value like url?parameter=123ABC
to have a second parameter passed, separate them by a ampersand like this
url?param1=123¶m2=Horse
Dan
| | Member | | Join Date: Jan 2009 Location: USA
Posts: 118
| | | re: ahref link with dynamic data
good morning - will post my results in a while thanks for the response!
| | Member | | Join Date: Jan 2009 Location: USA
Posts: 118
| | | re: ahref link with dynamic data
hello -
i've tried what your explaining to me. can you give me a better example with using sessions? to pass the variable to the next page.
so the query can pull multiple results. and each result will have its own id. i want that id to be set in session and passed to the next page.
i have it working fine with my current sessions on a single value but not multiple values.
so the multiple values will be in the array but only the choosen one will be passed.
i get an error when i try it says that the mysql result set error. i moved the session variable down below the query and still same error.
thanks in advance for your help,
theo werntz ii
|  | Expert | | Join Date: Feb 2008 Location: Australia
Posts: 913
| | | re: ahref link with dynamic data
I am not entirely sure what you have tried but you can store session variables like: - $_SESSION['id'] = 1;
-
$_SESSION['name'] = "John";
-
$_SESSION['email'] = "john@bytes.com";
-
etc.
Output is as simple as:
The problem with results from databases is that each row or result is an array itself. Making a 2D array is not a problem, but the $_SESSION array is not really designed for that, so serializing is required. This basically turns an array into a single value which can be stored in $_SESSION and then that value can be unserialized into an array again when needed. That's how I understand it atleast.
Can you include some code? You said you got a "mysql result set error"? Haven't seen that one before, but show us how you are handling the query and $_SESSIONs as I suspect there is some misunderstanding.
|  | Expert | | Join Date: Dec 2007 Location: Moon, Dark Side
Posts: 1,094
| | | re: ahref link with dynamic data
session singular variables he knows, arrays or multiple he doesn't.
Your myself result error is a different error. Debug that one first.
Did you read the php doc on serialize? Here's an example of what I was talking about : -
-
//page.php:
-
$myarr = array("foo","bar");
-
-
$_SESSION['myarr_s'] = serialize($myarr);
-
-
// secondpage.php
-
-
$myarr = unserialize($_SESSION['myarr_s']);
-
-
Echo the serialized variable to see what it looks like. It's just a coded string that php understand and can reconstruct.
Dan
| | Member | | Join Date: Jan 2009 Location: USA
Posts: 118
| | | re: ahref link with dynamic data
good morning -
thanks for the responses.
this is what i have so far:
i would not like to use the get url string from url for security reasons so im sticking with sessions.
i was able to get the session working for the link but its only storing one record id in the array here is my code: -
// 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>
-
yes i did read on serialize but didn't find a good way to use it with a mysql query. i just found that u needed to enter the array values.
could i use the serialize like: -
$myarr = array(mysql_query($query,0,'Id'));
-
-
$_SESSION['myarr_s'] = serialize($myarr);
-
-
$sesId=$_Session['myarr_s'];
-
-
<td><a href="url.php"><?php echo $sesId['Id']; ?></a></td>
-
-
$myarr = unserialize($_SESSION['myarr_s']);
-
thanks again in advance for your help,
|  | Moderator | | Join Date: Aug 2008 Location: Leipzig, Germany
Posts: 3,629
| | | re: ahref link with dynamic data Quote:
Originally Posted by wizardry -
$myarr = array(mysql_query($query,0,'Id'));
there are Database Abstraction Layers (e.g. PDO) that can return the complete SQL result as array. I'm not sure, whether saving the resource is a good idea.
|  | Moderator | | Join Date: Jun 2007 Location: York, England, with wolves.
Posts: 4,936
| | | re: ahref link with dynamic data Quote:
Originally Posted by Dormilich there are Database Abstraction Layers (e.g. PDO) that can return the complete SQL result as array. I'm not sure, whether saving the resource is a good idea. Off-topic: it annoys me that the PHP MySQL wrapper does not provide a native way to return ALL results into an array. I was considering writing a patch for the PHP MySQL extension to include this function - something like mysql_fetch_all().
|  | Moderator | | Join Date: Jun 2007 Location: York, England, with wolves.
Posts: 4,936
| | | re: ahref link with dynamic data Quote:
Originally Posted by wizardry good morning -
thanks for the responses.
this is what i have so far:
i would not like to use the get url string from url for security reasons so im sticking with sessions.
i was able to get the session working for the link but its only storing one record id in the array here is my code: -
// 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>
-
yes i did read on serialize but didn't find a good way to use it with a mysql query. i just found that u needed to enter the array values.
could i use the serialize like: -
$myarr = array(mysql_query($query,0,'Id'));
-
-
$_SESSION['myarr_s'] = serialize($myarr);
-
-
$sesId=$_Session['myarr_s'];
-
-
<td><a href="url.php"><?php echo $sesId['Id']; ?></a></td>
-
-
$myarr = unserialize($_SESSION['myarr_s']);
-
thanks again in advance for your help, You cannot serialize() a resource. Quote:
Originally Posted by php.net The value to be serialized. serialize() handles all types, except the resource-type. | | Member | | Join Date: Jan 2009 Location: USA
Posts: 118
| | | re: ahref link with dynamic data
markus -
could you give me a detail usage on dynamic session arrays?
or am i doing something wrong? i've been racking my brain with this; and googling(dynamic session arrays) ; the array is set but in the session variable it only outputs one variable.
have i not set the array correctly?
thanks in advance for your help.
| | Member | | Join Date: Jan 2009 Location: USA
Posts: 118
| | | re: ahref link with dynamic data
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);
-
?>
-
-
|  | | | | /bytes/about
We are a network of experts and professionals in IT and software development that help one another with answers to tough questions and share insights.
Get the best answers to your questions from over 226,272 network members.
|