Click to See Complete Forum and Search --> : Getting multiple info from a list menu


gazzwi86
10-07-2007, 07:07 PM
i have a list menu with sizes of images and there price next to it. the size is inserted to a table but would also like to get the price inserted into the table depending on the size chosen. i have very limited php skils and im really struggling with this at the moment so any help would be greatly apprecited.

Im assuming i will need to add an if statement something like:

//if (sel_item_size == '6x4 £6.00') {sel_item_price ==£6.00;}
//else if (sel_item_size == '7x5 £7.00') {sel_item_price ==£7.00;}
//else if (sel_item_size == '8x6 £8.00') {sel_item_price ==£8.00;}
//else (sel_item_size == '10x8 £12.00') {sel_item_price ==£12.00;}



heres the code for the page,

<?php
session_start();
//connect to database
$conn = mysql_connect("**", "***", "***") or die(mysql_error());
mysql_select_db("*",$conn) or die(mysql_error());

$display_block = "<h1>My Store - Item Detail</h1>";

//validate item
$get_item = "select c.id as cat_id, c.cat_title, si.item_title, si.item_price, si.item_desc, si.item_image from store_items as si left join store_categories as c on c.id = si.cat_id where si.id = $_GET[item_id]";
$get_item_res = mysql_query($get_item) or die (mysql_error());

if (mysql_num_rows($get_item_res) < 1) {
//invalid item
$display_block .= "<P><em>Invalid item selection.</em></p>";
} else {
//valid item, get info
$cat_id = mysql_result($get_item_res,0,'cat_id');
$cat_title = strtoupper(stripslashes(mysql_result($get_item_res,0,'cat_title')));
$item_title = stripslashes(mysql_result($get_item_res,0,'item_title'));
$item_price = mysql_result($get_item_res,0,'item_price');
$item_desc = stripslashes(mysql_result($get_item_res,0,'item_desc'));
$item_image = mysql_result($get_item_res,0,'item_image');

//make breadcrumb trail
$display_block .= "<P><strong><em>You are viewing:</em><br><a href=\"seestore.php?cat_id=$cat_id\">$cat_title</a> &gt; $item_title</strong></p>
<table cellpadding=3 cellspacing=3>
<tr>
<td valign=middle align=center><img src=\"$item_image\"></td>
<form method=post action=\"addtocart.php\">";

$display_block .= "
<p><strong>Select Colour:</strong>
<select name=\"sel_item_color\">";
$display_block .="
<option value=\"B&amp;W\">Black &amp; White</option>
<option value=\"Colour\">Colour</option>
</select>";

$display_block .= "
<p><strong>Select Size:</strong>
<select name=\"sel_item_size\">";
$display_block .="
<option value=\"6x4 - &pound;6.00\">6x4 &pound;6.00</option>
<option value=\"7x5 - &pound;7.00\">7x5 &pound;7.00</option>
<option value=\"8x6 - &pound;8.00\">8x6 &pound;8.00</option>
<option value=\"10x8 - &pound;12.00\">10x8 &pound;12.00</option>
</select>";

$display_block .= "
<P><strong>Select Quantity:</strong>
<select name=\"sel_item_qty\">";

for($i=1; $i<11; $i++) {
$display_block .= "<option value=\"$i\">$i</option>";
}

$display_block .= "
</select>
<input type=\"hidden\" name=\"sel_item_id\" value=\"$_GET[item_id]\">
<P><input type=\"submit\" name=\"submit\" value=\"Add to Cart\"></p>
</form>
</td>
</tr>
</table>";
}
?>
<HTML>
<HEAD>
<TITLE>My Store</TITLE>
</HEAD>
<BODY>
<?php echo $display_block; ?>
</BODY>
</HTML>

scragar
10-07-2007, 07:29 PM
you could split it on: "&pound;" in order to retrive the number, but realy I think it's best to just make it return a number instead of sizing info, then load sizes etc from an array or table of settings.
$input = split("&pound;", $_POST['sel_item_size']);
echo "size: ${input[0]}<br />
price: ${input[1]}";

gazzwi86
10-08-2007, 07:16 AM
not quite sure what you mean. ive create a second table with the sizes and there corressponding prices. if i understand you correctly i need to query the size now and get the result from the price field inserting it into the price column of the order table although im not sure how to do this. i cant access data from another table.