Quote:
|
Would it be possible to have the javascript pass the checked results on the Order page to SQL queries that display results and calculate price on the Confirmation page?
|
Every bit of info submitted from your checkboxes and teh like is beeing accessibel in the $_POST variable, the thing is, if you'd use a uniq description, like the ID tag, you would be able to do any form of operation directly from the results returned, that beeing calculate a price or extract further info about an item to display to the viewer.
When building the checkbox page, you'd fetch whatevver you have in your database and display it to the user, this is somethign like what my page is doing:
PHP Code:
/* select what we have in the database, and build the form for submitting */
$categories = @mysql_query("SELECT * FROM categories ORDER BY id", $DB_LINK);
while($category = @mysql_fetch_array($categories)){
$item_count = 1;
$body .= "<td valign='bottom'><font size='+2'><b>".$category['name']."</b></font> <input type='checkbox' name
='allbox".$category['id']."' onclick=\"checkAll('".$category['id']."');\" /> Check All
<table border='0' cellspacing='0' cellpadding='0' width='100%' style='border: 1px solid rgb(12, 13, 119);'>
<tr>
";
$items = @mysql_query("SELECT * FROM items WHERE category=\"".$category['id']."\" ORDER BY id", $DB_LINK);
while($item = @mysql_fetch_array($items)){
if(!(($item_count++) %2))
$body .= "</tr><tr><td valign='top'>
"; /* only two items valigned within a category */
else
$body .= "<td valign='top'>";
$body .= "<input type='checkbox' value='".$item['id']."' name='checkbox[".$category['id']."][]'><b>".$ite
m['name']."</b><br />
".$item['description']."</td>
";
}
As you can see from this, the building of the HTML code from the mysql-queries and loops is like thinking of it in 3D.. Or thats how I usualy visualise it while writing the code.
So to keep it simple, heres how I would fetch the things, once submit has been pressed, if you were to use the id's as values in your checkboxes:
PHP Code:
if(isset($_POST['checkbox'])){
/* we were called through the 'submit' button
* so we build the page accordingly
*/
$categories = @mysql_query("SELECT id FROM categories ORDER BY id", $DB_LINK);
$checked = $_POST['checkbox'];
while($category = @mysql_fetch_array($categories)){
foreach($checked[$category['id']] as $check){
$res = @mysql_query("SELECT * FROM items WHERE id='$check'", $DB_LINK);
while($row = @mysql_fetch_array($res)){
/* do whatever with what is fetched, name, description, price, etc. */
}
}
}
}