Jump to content


Photo

Pegar Valores Da Session


  • Faça o login para participar
2 replies to this topic

#1 jluiz28a

jluiz28a

    Novato no fórum

  • Usuários
  • 1 posts
  • Sexo:Não informado

Posted 03/07/2010, 22:10

Tenho este codigo abaixo que é um carrinho de compras, gostaria de saber como pego os valores deste session e colocar num banco de dados, ou simplismente mostra os dados desta session

<?php
session_start();
if(!isset($_SESSION['carrinho'])){
$_SESSION['carrinho'] = array();
$Lista = $_SESSION['carrinho'];
}

//adiciona produto

if(isset($_GET['acao'])){

//ADICIONAR CARRINHO
if($_GET['acao'] == 'add'){
$id = intval($_GET['id']);
if(!isset($_SESSION['carrinho'][$id])){
$_SESSION['carrinho'][$id] = 1;
}else{
$_SESSION['carrinho'][$id] += 1;
}
}

//REMOVER CARRINHO
if($_GET['acao'] == 'del'){
$id = intval($_GET['id']);
if(isset($_SESSION['carrinho'][$id])){
unset($_SESSION['carrinho'][$id]);
}
}

//ALTERAR QUANTIDADE
if($_GET['acao'] == 'up'){
if(is_array($_POST['prod'])){
foreach($_POST['prod'] as $id => $qtd){
$id = intval($id);
$qtd = intval($qtd);
if(!empty($qtd) || $qtd <> 0){
$_SESSION['carrinho'][$id] = $qtd;
}else{
unset($_SESSION['carrinho'][$id]);
}
}
}
}

}


?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR...nsitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
</head>

<body>
<table>
<caption>Carrinho de Compras</caption>
<thead>
<tr>
<th width="244">Produto</th>
<th width="79">Quantidade</th>
<th width="89">Pre&ccedil;o</th>
<th width="100">SubTotal</th>
<th width="64">Remover</th>
</tr>
</thead>
<form action="?acao=up" method="post">
<tfoot>
<tr>
<td colspan="5"><input type="submit" value="Atualizar Carrinho" /></td>
<tr>
<td colspan="5"><a href="cesta.php">Continuar Comprando</a></td>

</tfoot>
<tbody>
<?php
if(count($_SESSION['carrinho']) == 0){
echo '<tr><td colspan="5">Não há produto no carrinho</td></tr>';
}else{
require("conecta.php");
$total = 0;
foreach($_SESSION['carrinho'] as $id => $qtd){
$sql = "SELECT * FROM cad_livros WHERE cad_id= '$id'";
$qr = mysql_query($sql) or die(mysql_error());
$ln = mysql_fetch_assoc($qr);

$cad_descricao = $ln['cad_descricao'];
$cad_preco = number_format($ln['cad_preco'], 2, ',', '.');
$sub = number_format($ln['cad_preco'] * $qtd, 2, ',', '.');

$valorTotal += $ln['cad_preco'] * $qtd;

echo '<tr>
<td>'.$cad_descricao.'</td>
<td><input type="text" size="3" name="prod['.$id.']" value="'.$qtd.'" /></td>
<td>R$ '.$cad_preco.'</td>
<td>R$ '.$sub.'</td>
<td><a href="?acao=del&id='.$id.'">Remove</a></td>
</tr>';
}
$valorTotal = number_format($valorTotal, 2, ',', '.');
echo '<tr>
<td colspan="4">Total</td>
<td>R$ '.$valorTotal.'</td>
</tr>';
}
?>
<td colspan="5"><a href="cadastraPedido.php?acao=finaliza">Finalizar</a></td>
</tbody>

</form>
</table>

</body>
</html>

#2 rsantos

rsantos

    Turista

  • Usuários
  • 54 posts
  • Sexo:Masculino

Posted 04/07/2010, 00:18

<?php echo $_SESSION['carrinho'][1]; ?>

Ou para ver tudo que tem gravado em sessão:

<?php print_r($_SESSION); ?>

#3 JeffMalm

JeffMalm

    Super Veterano

  • Usuários
  • 12254 posts
  • Sexo:Feminino
  • Localidade:Mount Carey

Posted 09/02/2023, 11:08

Lesion development in these 2 models may be influenced differently by other aspects apart from plasma lipids, such as monocyte adhesion 29 and endothelium function, 30 which can be modulated by different diets generic azithromycin price
They recommend against routine monitoring with anti factor Xa level measurements Grade 1A is stromectol available in canada PLoS One, 2011, 6 3 17815 10
Location matters osteoblast and osteoclast distribution is modified by the presence and proximity to breast cancer cells in vivo should i take 1mg or 5mg of propecia norepinephrine decreases effects of insulin inhaled by pharmacodynamic antagonism
isotretinoin tablets buy SAHA inhibited the proliferation of 4T1
Read on to know more priligy amazon uk
reputable online levitra This medication has black box warnings I was never told, what a mess
stromectol order Formation of AGEs occur not only under conditions of hyperglycemia and enhanced glycolysis in cancer but also with ageing, inflammation and oxidative stress 10, 48
Patients with a positive biopsy received ICE followed by autologous stem cell transplantation ivermectin 3mg
There is no situation where fracked gas will lower prices cost of propecia ireland SOURCES Jon JarlÐÑv Rasmussen, MD, PhD, postdoctoral scientist, Department of Endocrinology, Rigshospitalet, University Hospital of Copenhagen, Denmark; Bradley Anawalt, MD, chief, medicine, University of Washington Medical Center, Seattle, and board- certified physician, Endocrine and Diabetes Care Center, Seattle; Journal of Clinical Endocrinology Metabolism, March 9, 2021




1 user(s) are reading this topic

0 membro(s), 1 visitante(s) e 0 membros anônimo(s)

IPB Skin By Virteq