Português Posted July 3, 2012 at 06:02 PM Report Share #467065 Posted July 3, 2012 at 06:02 PM Boas , no meu projeto tenho a página "ver_material.php" <table border="2px" class="tabela2"> <thead> <tr> <th width="35%">Nome</th> <th width="10%">Valor</th> <th width="10%">Data</th> <th width="10%">Estado</th> <th width="10%">Comprar</th> <th width="10%"><strong>Adicionar ao carrinho</strong></th> </tr> </thead> <?php while ($res = mysql_fetch_array($resultado)) { extract($res); $nmaterial = $res['nmaterial']; $nome = $res['nome']; $valor = $res['valor']; $data = $res['data']; echo '<tr>'; echo '<td width="800">'.$nome.'</td>'; echo '<td>'.$valor.' €</td>'; echo '<td>'.$data.'</td>'; echo '<td>'; // estado 0: disponivel // estado 1: comprado if ($estado==0) { echo '<span style="color: Green">Disponível</span>'; echo'<td>'; echo '<img src="imagens/check.png"'; echo'</td>'; echo'<td>'; echo '<a href="carrinho.php?&nmaterial='.$nmaterial.'&acao=adicionar"><img src="imagens/shopping.png"</a>'; echo'</td>'; } else { echo '<span style="color: Red">Comprado</span>'; echo'<td>'; echo '<img src="imagens/dialog-close.png"'; echo'</td>'; } echo '</tr>'; } echo '</table>'; } ?> </table> e o carrinho: <?php $resultado = mysql_query($sql) or die (mysql_error()); if (@mysql_num_rows($resultado) == 0) echo "Não existem registos"; while($linha=mysql_fetch_assoc($resultado)){ extract($linha); ?> <form action="carrinho.php" id="carrinho" name="carrinho"> <table border="0" class="tabela2"> <tr> <td>Número do material:</td> <td><input readonly type="text" name="nmaterial" maxlength="80" value="<?=$linha['nmaterial'] ?>" /></td> </tr> <tr> <td>Nome:</td> <td><input readonly type="text" name="nome" maxlength="80" value="<?=$linha['nome'] ?>" /></td> </tr> <tr> <td>Valor:</td> <td><input readonly type="text" name="valor" maxlength="80" value="<?=$linha['valor'] ?>" /></td> </tr> <tr> <td colspan="2"> <input type="button" name="voltar" value="Voltar" onclick="location.href='ver_material.php';" /> </td> </tr> </table> </form> <?php if ($acao == "adicionar" ) { $query= 'INSERT INTO carrinho(ncarrinho, nmaterial, nome, valor) VALUES ("'.$ncarrinho.'", "'.$nmaterial.'", "'.$nome.'", '.$valor.')'; mysql_query($query, $db) or die('Erro ao inserir os valores'); } } ?> </div> </div> </body> </html> Eu gostava que ao clicar na "<img src="imagens/shopping.png"</a>" , voltasse á página "ver_material.php" e troca-se a imagem "echo '<span style="color: Green">Disponível</span>';" para "echo '<span style="color: Red">Comprado</span>';". Precisava mesmo de ajuda ... 😕 Obrigado pela atenção 🙂 Link to comment Share on other sites More sharing options...
HappyHippyHippo Posted July 3, 2012 at 06:20 PM Report Share #467070 Posted July 3, 2012 at 06:20 PM para voltar imediatamente para a página "ver_material.php" podes usar o seguinte código no final do script "carrinho.php" header("ver_material.php"); die(); Nota : não podes ter nenhum output nesta página porque senão vais ter logo um erro na linha "header" para alterar a apresentação da segunda imagem, basta verificar se o produto já se encontra registado no carrinho se sim, uma imagem, se não, a outra imagem ... IRC : sim, é algo que ainda existe >> #p@p Portugol Plus Link to comment Share on other sites More sharing options...
Português Posted July 3, 2012 at 07:07 PM Author Report Share #467086 Posted July 3, 2012 at 07:07 PM Ok obrigado pela ajuda HappyHippyHippo, vou tentar 👍 Link to comment Share on other sites More sharing options...
yoda Posted July 3, 2012 at 07:55 PM Report Share #467100 Posted July 3, 2012 at 07:55 PM ** header("Location: ver_material.php"); before you post, what have you tried? - http://filipematias.info sense, purpose, direction Link to comment Share on other sites More sharing options...
Português Posted July 3, 2012 at 08:11 PM Author Report Share #467109 Posted July 3, 2012 at 08:11 PM Desculpa a ignorância , mas não estou a conseguir fazer fazer a mudança de imagens ... 😕 Ainda sou muito principiante , ou seja , não percebo lá muita coisa de programação 😕 Se colocar assim , insere na base de dados: <?php if ($acao == "adicionar" ) { $query= 'INSERT INTO carrinho(ncarrinho, nmaterial, nome, valor) VALUES ("'.$ncarrinho.'", "'.$nmaterial.'", "'.$nome.'", '.$valor.')'; mysql_query($query, $db) or die('Erro ao inserir os valores'); } } header("Location: ver_material.php"); ?> Obrigado pela ajuda yoda 😉 Link to comment Share on other sites More sharing options...
Português Posted July 3, 2012 at 11:39 PM Author Report Share #467173 Posted July 3, 2012 at 11:39 PM Preciso de ajuda urgentemente 😕 Link to comment Share on other sites More sharing options...
HappyHippyHippo Posted July 4, 2012 at 09:03 AM Report Share #467206 Posted July 4, 2012 at 09:03 AM Desculpa a ignorância , mas não estou a conseguir fazer fazer a mudança de imagens ... 😕 Ainda sou muito principiante , ou seja , não percebo lá muita coisa de programação 😕 Se colocar assim , insere na base de dados: <?php if ($acao == "adicionar" ) { $query= 'INSERT INTO carrinho(ncarrinho, nmaterial, nome, valor) VALUES ("'.$ncarrinho.'", "'.$nmaterial.'", "'.$nome.'", '.$valor.')'; mysql_query($query, $db) or die('Erro ao inserir os valores'); } } header("Location: ver_material.php"); ?> Obrigado pela ajuda yoda 😉 não tens claramente o código todo do script (ou se tiveres está descaradamente muito mal) IRC : sim, é algo que ainda existe >> #p@p Portugol Plus Link to comment Share on other sites More sharing options...
Português Posted July 4, 2012 at 04:49 PM Author Report Share #467294 Posted July 4, 2012 at 04:49 PM Vou tentar investigar , obrigado 🙂 Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now