weely
07-25-2006, 02:39 AM
Hello there,
pls I need help. I want to assign values to session variables when a link is clicked. But it does not seem to work. I have looked at similar threads (How to use $_POST) but it does not really answer my question.
Is there any other way to do this? please it urgent cos this is my uni project. Thanks
Here a snippet of the code (if it helps): {I have highlighted the problem area}
<?php
function get_list(){ //retrieve and displays results from the database
$conn = connect();
$date = set_date();
$list = "select a.agent_no, a.week_end, b.firstname, b.initial, b.surname from timesheet a, agent b where a.week_end = '$date' and a.staged_to = 'S' and a.agent_no = b.agent_no"; //include coy_code, location in query
$result = mysql_query($list, $conn);
echo mysql_num_rows($result)." Record(s) Found!";
echo "<table class=\"resultset\">";
echo "<tr><td>Name</td><td>Agent Number</td><td>Week Ending</td><td>Location</td><td>View Details</td></tr>";
$count = 0;
while($result_array = mysql_fetch_array($result)){
$agent_no = $result_array['agent_no'];
$week_end = $result_array['week_end'];
$firstname = $result_array['firstname'];
$initial = $result_array['initial'];
$surname = $result_array['surname'];
// $location = $result['location'];
if($count%2 != 0){ //to change background colour
echo "<tr class=\"switch\"><td>$firstname $initial $surname</td><td>$agent_no</td><td>$week_end</td><td>$location</td><td><a onclick=\"<?php set_globals($firstname, $surname, $agent_no, $date); ?>\" href=\"view.php\">View</a></td></tr>";
}
else{
echo "<tr><td>$firstname $initial $surname</td><td>$agent_no</td><td>$week_end</td><td>$location</td><td><a href=\"view.php\">View</a></td></tr>";
}
$count++;
}
echo "</table>";
}
function set_globals($a, $b, $c, $d){
$_SESSION[firstname] = $a;
$_SESSION[surname] = $b;
$_SESSION[agent_no] = $c;
$_SESSION[week_end] = $d;
}
?>
pls I need help. I want to assign values to session variables when a link is clicked. But it does not seem to work. I have looked at similar threads (How to use $_POST) but it does not really answer my question.
Is there any other way to do this? please it urgent cos this is my uni project. Thanks
Here a snippet of the code (if it helps): {I have highlighted the problem area}
<?php
function get_list(){ //retrieve and displays results from the database
$conn = connect();
$date = set_date();
$list = "select a.agent_no, a.week_end, b.firstname, b.initial, b.surname from timesheet a, agent b where a.week_end = '$date' and a.staged_to = 'S' and a.agent_no = b.agent_no"; //include coy_code, location in query
$result = mysql_query($list, $conn);
echo mysql_num_rows($result)." Record(s) Found!";
echo "<table class=\"resultset\">";
echo "<tr><td>Name</td><td>Agent Number</td><td>Week Ending</td><td>Location</td><td>View Details</td></tr>";
$count = 0;
while($result_array = mysql_fetch_array($result)){
$agent_no = $result_array['agent_no'];
$week_end = $result_array['week_end'];
$firstname = $result_array['firstname'];
$initial = $result_array['initial'];
$surname = $result_array['surname'];
// $location = $result['location'];
if($count%2 != 0){ //to change background colour
echo "<tr class=\"switch\"><td>$firstname $initial $surname</td><td>$agent_no</td><td>$week_end</td><td>$location</td><td><a onclick=\"<?php set_globals($firstname, $surname, $agent_no, $date); ?>\" href=\"view.php\">View</a></td></tr>";
}
else{
echo "<tr><td>$firstname $initial $surname</td><td>$agent_no</td><td>$week_end</td><td>$location</td><td><a href=\"view.php\">View</a></td></tr>";
}
$count++;
}
echo "</table>";
}
function set_globals($a, $b, $c, $d){
$_SESSION[firstname] = $a;
$_SESSION[surname] = $b;
$_SESSION[agent_no] = $c;
$_SESSION[week_end] = $d;
}
?>