Jump to content

session variable set from link table


ruraldev

Recommended Posts

Hi

 

Hope someone can point me it the right direction with this query.

 

I have a table of mysql query results on my page each of which is a link, how can I set a session variable depending on which link is chosen, each link has 2 fields, link_id and link_name, link_name is the visable item and link_id is the value I would like to set the variable to.

 

Thanks

 

Gordon

Link to comment
https://forums.phpfreaks.com/topic/174485-session-variable-set-from-link-table/
Share on other sites

if(isset($link1)) { 
  $_SESSION['var'] = $link_id1;
} else {
  $_SESSION['var'] = $link_id2;
}

? An if/else statement works; if it gets more complicated, you can do a switch/case.

 

It'd help if there were code attached to see what you are trying to do.

Happy to add to code if it helps:

 

<?php session_start(); require_once('Connections/cycle.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;

}

}

 

$maxRows_Recordset1 = 25;

$pageNum_Recordset1 = 0;

if (isset($_GET['pageNum_Recordset1'])) {

  $pageNum_Recordset1 = $_GET['pageNum_Recordset1'];

}

$startRow_Recordset1 = $pageNum_Recordset1 * $maxRows_Recordset1;

 

$colname_Recordset1 = "-1";

if (isset($_SESSION['location'])) {

  $colname_Recordset1 = $_SESSION['location'];

}

mysql_select_db($database_cycle, $cycle);

$query_Recordset1 = sprintf("SELECT route_id, route_name FROM route WHERE location_id = %s ORDER BY route_name ASC", GetSQLValueString($colname_Recordset1, "int"));

$query_limit_Recordset1 = sprintf("%s LIMIT %d, %d", $query_Recordset1, $startRow_Recordset1, $maxRows_Recordset1);

$Recordset1 = mysql_query($query_limit_Recordset1, $cycle) or die(mysql_error());

$row_Recordset1 = mysql_fetch_assoc($Recordset1);

 

if (isset($_GET['totalRows_Recordset1'])) {

  $totalRows_Recordset1 = $_GET['totalRows_Recordset1'];

} else {

  $all_Recordset1 = mysql_query($query_Recordset1);

  $totalRows_Recordset1 = mysql_num_rows($all_Recordset1);

}

$totalPages_Recordset1 = ceil($totalRows_Recordset1/$maxRows_Recordset1)-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>

</head>

 

<body>

<p>Select a route or refine your criteria</p>

<form id="form1" name="form1" method="post" action="">

  <table border="1">

    <tr>

      <td>route_id</td>

      <td>route_name</td>

    </tr>

    <?php do { ?>

    <tr>

      <td><?php echo $row_Recordset1['route_id']; ?></td>

      <td><a href="arearoutes.php?countrytabs=3"><?php echo $row_Recordset1['route_name']; ?></a></td>

    </tr>

    <?php } while ($row_Recordset1 = mysql_fetch_assoc($Recordset1)); ?>

  </table>

</form>

<p><?php echo $_SESSION['location']; ?>

  <?php $_SESSION['route'] = $row_Recordset1['route_id']; ?></p>

</body>

</html>

<?php

mysql_free_result($Recordset1);

?>

 

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.