Jump to content

Store mySql result in session to reuse


dante7921

Recommended Posts

Hello,

 

New member here, first time post. After stumbling upon this site, I have to say, I am certainly impressed with what I see. I'm hoping I can get some help with my issue.

 

What I'd like to do is store the results of a mySql query in a session (or some other method) to redisplay.

 

I have a search engine that displays results based on keyword input from a mySql database. These results are turned into links. Once a user clicks one of the results links, the remaining results are gone. I need to store them to redisplay them on the page the user is taken to after clicking on one of the links.

 

I know this has to be possible but all my research and testing have given me no results.

 

Any help would be much appreciated. Here is the code that searches the db and returns the results. I use smarty so if someone can make this work, I can change it to work with smarty.

 

//Search Results Found
for ($x=0;$x<mysql_num_rows($r_list);$x++){
	$list[$x] = mysql_fetch_assoc($r_list);
      mysql_query("UPDATE $pds_liststats SET sub_views=sub_views+1 WHERE list_id='$list_upd';"); 
	$cr = mysql_query("SELECT id FROM $pds_coupon WHERE TO_DAYS(d_start) <= TO_DAYS(NOW()) AND TO_DAYS(d_expire) > TO_DAYS(NOW()) AND lid='$list_upd';");
      $list[$x]['coupon_check'] = mysql_num_rows($cr);
      mysql_free_result($cr); 
	$check_file = "sublist".$list[$x][level].".tpl";
	if (is_readable("templates/$config[deftpl]/sublist/$check_file")){
		$list[$x][subfile] = $check_file;
	}else{
		$list[$x][subfile] = "sublist0.tpl";
	}
	if($x%2){
		$list[$x][bgcolor] = $config['bg_dark'];
	}else{
		$list[$x][bgcolor] = $config['bg_light'];
	}
	$check_file = $list[$x]['id'].".".$list[$x]['logo_ext'];
	if ($list[$x]['logo_ext'] != "" AND is_readable("logo/$check_file")){
		$list[$x]['logo'] = "$config[mainurl]/logo/$check_file?".rand();
	}
	$list[$x]['mod_firm'] = str_replace(" ","_",$list[$x]['firm']);
	$list[$x]['mod_firm'] = str_replace('/',"-",$list[$x]['mod_firm']);
	$list[$x]['mod_firm'] = str_replace("/","-",$list[$x]['mod_firm']);
	$list[$x]['sxtra1'] = stripslashes(substr($list[$x]['xtra_1'],0,200)); 
	$list[$x]['tip_firm'] = addslashes(htmlentities($list[$x]['firm']));
      $list[$x]['tip_phone'] = addslashes(htmlentities($list[$x]['phone']));
      $list[$x]['tip_address'] = addslashes(htmlentities(str_replace("\r\n","<br>",$list[$x]['address1'])));
      $list[$x]['tip_description'] = addslashes(htmlentities(str_replace("\r\n","<br>",$list[$x]['description'])));
}
SmartyPaginate::setTotal($f1['total']);
SmartyPaginate::assign($tpl);
if( !empty($csearch_sql) ){
      $rc = mysql_query("SELECT * FROM $pds_category WHERE f_mt = '1' $csearch_sql ORDER BY title;");
      for($x=0;$x<mysql_num_rows($rc);$x++){
         $clist[$x] = mysql_fetch_assoc($rc);
         $clist[$x]['title'] = $language->desc('category',$lang_set,$clist[$x]['id']);
         if($config['rewrite']){
            $mod_id = $clist[$x]['id'];
            $mod_title = str_replace(' ','_',getCatPath($clist[$x]['id']));
            $mod_title = str_replace('/','-',$mod_title);
            $clist[$x]['href'] = "<a href=\"./$mod_title-$mod_id-0.html\">".$clist[$x]['title']."</a>";
         }else{
            $clist[$x]['href'] = "<a href=\"index.php?cat=".$clist[$x]['id']."\">".$clist[$x]['title']."</a>";
         }
      }
   } 
}else{
//No Results Found
 if( !empty($csearch_sql) ){
      $rc = mysql_query("SELECT * FROM $pds_category WHERE f_mt = '1' $csearch_sql ORDER BY title;");
      for($x=0;$x<mysql_num_rows($rc);$x++){
         $clist[$x] = mysql_fetch_assoc($rc);
         $clist[$x]['title'] = $language->desc('category',$lang_set,$clist[$x]['id']);
         if($config['rewrite']){
            $mod_id = $clist[$x]['id'];
            $mod_title = str_replace(' ','_',getCatPath($clist[$x]['id']));
            $mod_title = str_replace('/','-',$mod_title);
            $clist[$x]['href'] = "<a href=\"./$mod_title-$mod_id-0.html\">".$clist[$x]['title']."</a>";
         }else{
            $clist[$x]['href'] = "<a href=\"index.php?cat=".$clist[$x]['id']."\">".$clist[$x]['title']."</a>";
         }
      }
   } 
}

 

Thanks so much, I look forward to any replies.

 

Joshua

Link to comment
https://forums.phpfreaks.com/topic/161141-store-mysql-result-in-session-to-reuse/
Share on other sites

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.