Forum Moderators: coopster
I have a form with a repeating table display data from MySQL, ie, invoice numbers and invoice pricing.
I need to be able to select which invoices someone wants to pay via checkboxes. From here, I need to be able to display the corresponding records on another page where I can SUM() the invoice totals to give a price to be paid.
I've never used array's before but believe this is how it should be done. My brain is currently fried and I'm struggling...
Any help would be greatly appreciated.
Thanks
Justin
<input type="checkbox" name="mySelection[]" value="dog">
<input type="checkbox" name="mySelection[]" value="cat">
<input type="checkbox" name="mySelection[]" value="fish">
you will get an array that looks like this:
$mySelection[0] = "dog";
$mySelection[1] = "cat";
$mySelection[2] = "fish";
So you could use your array data in your query like this:
WHERE user = 'username' AND id = '$mySelection[0]'
if you wanted to search for id='dog'
In this case where you most likely want to search by the entire selection you could run through the array n times and generate a dynamic piece of sql to accommodate for different selections:
<?
for($i=0;$i<count($mySelection);$i++){
$someSQL .= "id='$mySelection[$i]' OR ";
}
?>
and then alter your query to something like this:
WHERE user = 'username' AND ($moreSQL)
To register the array in the session all you need to do is session_register('CheckBoxArrayName').
As soon as you use the []'s you're making a reference to a value in the array.
Hope that makes some sense.
Though I am still having problems to extract the info from the database. I am using Dreamweaver in this and have included the code for the database select. Please can someone have a look and tell me where I'm going wrong.
I'm not totally sure of where to place the sql code you have mentioned.
Thanks
Justin
<?php
$checked_Recordset1 = "0";
if (isset($_SESSION['checkboxed'])) {
$checked_Recordset1 = (get_magic_quotes_gpc())? $_SESSION['checkboxed'] : addslashes($_SESSION['checkboxed']);
}
$colname_Recordset1 = "1";
if (isset($_SESSION['MM_Username'])) {
$colname_Recordset1 = (get_magic_quotes_gpc())? $_SESSION['MM_Username'] : addslashes($_SESSION['MM_Username']);
}
mysql_select_db($database_xerox, $xerox);
$query_Recordset1 = sprintf("SELECT * FROM job WHERE company = '%s' AND id = '%s'", $colname_Recordset1,$checked_Recordset1);
$Recordset1 = mysql_query($query_Recordset1, $xerox) or die(mysql_error());
$row_Recordset1 = mysql_fetch_assoc($Recordset1);
$totalRows_Recordset1 = mysql_num_rows($Recordset1);
?>