Home › Forums › JavaScript › need help making a script
- This topic is empty.
-
AuthorPosts
-
December 16, 2009 at 9:21 am #27222
skullcrusher
MemberHi everyone.
Hi need help to build a script, here is what i want..
i have two pages, first for the produts, second a quote form page. i whant thoose products have an icon that when the user clicks its adds to some database and then appears in the quote page with some more inputs (width, height, quantity) of the product.
Example: the user added product #1 to quote page;
Quote:products added:product #1 – reference bla bla bla
quantity: __________________
width: __________________
height: __________________product #2 – reference bla bla bla
quantity: __________________
width: __________________
height: __________________(send form)
and the items always appears when in the same session…
help please! dont know where to start.. thanks :)
December 21, 2009 at 6:17 am #68389skullcrusher
MemberNo one?
December 21, 2009 at 10:48 am #68412BaylorRae
MemberI would save the persons shopping cart in a PHP session separated with commas.
Code:$_SESSION[‘user_cart’] = ‘5,5,2,4,2’;Then use jQuery to send information to a php page to add to the session.
Code:jQuery(document).ready(function($) {$(‘.product’).click(function() {
// The link will look like this
// Add Product
var prod_id = $(this).attr(‘rel’).replace(/id-/, ”);$.get(‘add2cart.php’, {item_id: prod_id});
return false;
});});
// The PHP page
Code:And then loop through the session to display each item
Code:$quantity ) :
echo $id . ‘ = ‘ . $quantity . ‘
‘;
endforeach;}else
echo “Your cart is empty”;
?>In the last foreach, you’ll want to make a function to get the item’s title from the database.
Similar to this.Code:function title_from_id($id) {
$id = mysql_real_escape_string($id);
$sql = “SELECT * FROM `products` WHERE `id` = ‘$id'”;
$res = mysql_query($sql) or die(mysql_error());
$row = mysql_fetch_assoc($res);
return $row[‘title’];
}December 21, 2009 at 10:58 am #68416BaylorRae
MemberI’ve zipped up all my files that I used to test this.
December 21, 2009 at 11:13 am #68419skullcrusher
MemberYaiks! Thanks man..
1. There is anyway to adapte the script to use prototype instead of jquery? (its the library that im using in the page)
2. Can i put the product name like..
<a rel="id-product name" class="product" href="#">Add Product</a>
December 21, 2009 at 4:50 pm #68462BaylorRae
MemberI don’t know prototype so you’ll have to look through the documentation.
If you want to use the product name, then it should work just like that.
December 22, 2009 at 5:17 am #68508skullcrusher
MemberOk, thank you. One more thing: whats the code to a "remove" icon?
Edited: 2º question.. i want to send the data by email.
Code:$nomeprod = $_POST[“Nomeprod”];
$comprimento = $_POST[“Comprimento”];
$largura = $_POST[“Largura”];
$altura = $_POST[“Altura”];
$consumo = $_POST[“Consumo”];Code:Produto: $nomeprod
Comprimento: $comprimento
Largura: $largura
Altura: $altura
Consumo: $consumoBasiclly is that. But i want this for every products in the cart.. how can i change to dynnamic variables?
December 28, 2009 at 11:04 am #68721skullcrusher
MemberThe problem of sending data by email is solved.. i just need to code a "remove" button.
December 30, 2009 at 7:55 am #68779skullcrusher
Memberthe code for remove button…
Code:if( isset($_SESSION[‘user_cart’]) ) {
if ($numero > 1) {
$del = “,”;
$del .= $_GET[‘del_id’];
$_SESSION[‘user_cart’] = str_replace($del, “”, $_SESSION[‘user_cart’]);} else {
unset($_SESSION[‘user_cart’]);
}}else {
echo “erro”;
}Its working.. just one problem. Cant remove the first item, becase dont have the ‘,’ before.. how can i solve it? help please :)
PROBLEM SOLVED, here is the solution:
Code:if( isset($_SESSION[‘user_cart’]) ) {
if ($numero > 1) {
if ($items[0] == $_GET[‘del_id’]) {$del = $_GET[‘del_id’];
$del .= “,”;
$_SESSION[‘user_cart’] = str_replace($del, “”, $_SESSION[‘user_cart’]);} else {
$del = “,”;
$del .= $_GET[‘del_id’];
$_SESSION[‘user_cart’] = str_replace($del, “”, $_SESSION[‘user_cart’]);}
} else {
unset($_SESSION[‘user_cart’]);
}}else {
echo “erro”;
} -
AuthorPosts
- The forum ‘JavaScript’ is closed to new topics and replies.