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
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
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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

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