RSS Forums RSS
Please support our PHP advertiser: Lunarpages PHP Web Hosting
Views: 3212 | Replies: 1
Reply
Join Date: Apr 2005
Posts: 15
Reputation: vipula is an unknown quantity at this point 
Rep Power: 4
Solved Threads: 0
vipula vipula is offline Offline
Newbie Poster

PHP Session Problem

  #1  
Mar 14th, 2007
Hi
I have a website that can search for journal article and display it page by page. when you search, the results are displayed with check boxes and people can select items by ticking the check boxes. I am using PHP session to store checked items until they display selected items. It is woking with the 1st search. But if I do a second search the selection dont work. If I want it to wok I have to close the window and have to open a new window and seacrh, then it will work. Can any expert see what is the wrong with this script.

[PHP]<?php
session_start();


// catch selected items
if(isset($_REQUEST['items'])) {
$items = $_REQUEST['items'];
}
else {
$items = array();
}

// get items from session
$sesItems = array();
if(isset($_SESSION['sItems'])) {
$sesItems = $_SESSION['sItems'];
}
// add new items to session list
foreach($items as $item) {
if(!in_array($item, $sesItems)) {
array_push($sesItems, $item);
}
}
$itemCount = count($sesItems); // get item count
$_SESSION['sItems'] = $sesItems; // set items back to session



$db_host="";
$db_name="";
$db_user="";
$db_pass="";

$per_page=20;

$connection=mysql_connect($db_host, $db_user, $db_pass);
mysql_select_db($db_name, $connection);
$name=$_REQUEST['name'];
$lastSearch = $_SESSION['sName'];

//echo 'name: '. $name. ' last search: ' .$lastSearch;

if(isset($lastSearch) && $lastSearch != $name) { // new search
$itemCount = 0;
unset($_SESSION['sItems']);
}
else {
$_SESSION['sName'] = $name;
}

if($_REQUEST['mode'] == 'saved') {
$itemsCsv = implode(',', $sesItems);
$sql="SELECT COUNT(*) as total FROM journal WHERE rid IN ($itemsCsv)";
$sql_result=mysql_query($sql, $connection) or die("Cannot find Server: ".mysql_error());
$sql_result_array=mysql_fetch_array($sql_result);
$total=$sql_result_array['total'];
$sql="SELECT * FROM journal WHERE rid IN ($itemsCsv) ORDER BY DP DESC";
}
else {
$sql="SELECT COUNT(*) as total FROM journal WHERE match (FAU, TI, AU, SO, PT, DP, MESH, KW, TA, AD, ISSN, NOTE) AGAINST ('$name' in boolean mode) ORDER BY DP DESC";
$sql_result=mysql_query($sql, $connection) or die("Cannot find Server: ".mysql_error());
$sql_result_array=mysql_fetch_array($sql_result);
$total=$sql_result_array['total'];
$sql="SELECT * FROM journal WHERE match (FAU, TI, AU, SO, PT, DP, MESH, KW, TA, AD, ISSN, NOTE) AGAINST ('$name' in boolean mode) ORDER BY DP DESC";
}

if ($total=="0"){$search_result="No Results Found</p>";}
elseif ($total > 0){$search_result="<p class='error'>".$total. " Articles Found</p>";}



if (empty($_REQUEST['result_set']))
{
$result_set=0;
$sql.=" LIMIT $result_set, $per_page";

}
else
{
$result_set=$_REQUEST['result_set'];
$sql.=" LIMIT $result_set, $per_page";
}
$sql_result=mysql_db_query($db_name, $sql);
$sql_rows=mysql_num_rows($sql_result);
?>[/PHP]
AddThis Social Bookmark Button
Reply With Quote  
Join Date: Jul 2006
Posts: 191
Reputation: vssp is an unknown quantity at this point 
Rep Power: 3
Solved Threads: 5
vssp vssp is offline Offline
Junior Poster

Re: PHP Session Problem

  #2  
Mar 15th, 2007
I think ur session value unset your code. May be ur session variable and some other variables same in your code that scenario session variable unset
Thanks
VSSP
Reply With Quote  
Reply

Only community members can participate in forum threads. You must register or log in to contribute.

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)

 

Thread Tools Display Modes
Forums | Blogs | Tutorials | Code Snippets | Whitepapers | RSS Feeds | Advertising
All times are GMT -4. The time now is 2:51 pm.
Newsletter Archive - Sitemap - Privacy Statement - Contact Us
Forum system based on vBulletin Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC