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 page:]
products added:
product #1 - reference bla bla bla quantity: __________________ width: __________________ height: __________________
product #2 - reference bla bla bla quantity: __________________ width: __________________ height: __________________
(send form)
[/quote page]
and the items always appears when in the same session...
// Loop through items to get quantity foreach( $items as $item ) : if( isset($item_quantity[$item]) ) $item_quantity[$item]++; else $item_quantity[$item] = 1; endforeach;
// Loop through items again to // show title and quantity foreach( $item_quantity as $id => $quantity ) : echo $id . ' = ' . $quantity . '<br />'; 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.
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']; }
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 page:]
products added:
product #1 - reference bla bla bla
quantity: __________________
width: __________________
height: __________________
product #2 - reference bla bla bla
quantity: __________________
width: __________________
height: __________________
(send form)
[/quote page]
and the items always appears when in the same session...
help please! dont know where to start.. thanks :)
Then use jQuery to send information to a php page to add to the session.
jQuery(document).ready(function($) {
$('.product').click(function() {
// The link will look like this
// <a rel=\"id-2\" class=\"product\" href=\"#\">Add Product</a>
var prod_id = $(this).attr('rel').replace(/id-/, '');
$.get('add2cart.php', {item_id: prod_id});
return false;
});
});
// The PHP page
And then loop through the session to display each item
In the last foreach, you'll want to make a function to get the item's title from the database.
Similar to this.
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'];
}
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>
If you want to use the product name, then it should work just like that.
Edited: 2º question.. i want to send the data by email.
Basiclly is that. But i want this for every products in the cart.. how can i change to dynnamic variables?
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:
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\";
}