Jump to content

Session help


Bravat

Recommended Posts

How to add more data into $_SESSION? I have following code:

	if(isset($_GET['poredi']) && $_GET['poredi'] == "upo"){
	$idp = intval($_POST['idp']);
				$sql = "SELECT * FROM product
			WHERE product_id={$idp}";
		$query=mysql_query($sql);
		if(mysql_num_rows($query)!=0){
			$row=mysql_fetch_array($query);				
			$_SESSION['poredi'] = $row['product_id'];

		} 
}

 

On click it need to store more product_id, and after that i have to be able to do query with data (find all data with product_id)?

 

Link to comment
https://forums.phpfreaks.com/topic/227807-session-help/
Share on other sites

Do get the session to store an array of product_id's you would do:

[code=php:0]   if(isset($_GET['poredi']) && $_GET['poredi'] == "upo"){
      $idp = intval($_POST['idp']);
               $sql = "SELECT * FROM product
            WHERE product_id={$idp}";
         $query=mysql_query($sql);

        $ids = array();

         if(mysql_num_rows($query)!=0){
            $row=mysql_fetch_array($query);            
            $ids[] = $row['product_id'];
            
         }
         $_SESSION['poredi'] = $ids;
   }
      

Link to comment
https://forums.phpfreaks.com/topic/227807-session-help/#findComment-1174741
Share on other sites

That does the job, but now i am stumble upon the query. Here is code (not working):

<?php
			if(isset($_SESSION['poredi'])){	
			$idp = $_SESSION['poredi'];				
				$sql="SELECT * FROM product WHERE product_id IN (";					
				foreach($_SESSION['poredi'] as $id) {
					$sql.=$id.",";
				}					
				$sql=substr($sql, 0, -1).") ORDER BY model ASC";
				$query=mysql_query($sql);
				while($row=mysql_fetch_array($query)){						
				?>
					<?php echo "<span class=\"korpa\">" . $row['model'] ?> 
                     <?php
				}
			?>

 

Link to comment
https://forums.phpfreaks.com/topic/227807-session-help/#findComment-1174744
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.