/    Sign up×
Community /Pin to ProfileBookmark

Compare checked values

Hi there!

I tried finding my answer by searching through posts, so far no luck, so I’m hoping anyone of you can help me out on this one. At the moment I’m working on a invoice page, before you can invoice you need an order, but each invoice you make may contain multiple orders.

What I’ve got, A while loop that shows all non invoiced orders with a checkbox in front of it. When you check multiple checkboxes it first has to check if the customer ID (klant_id) is the same, you can’t raise 1 invoice for 2 different customers. So far my script can tell me if I selected 2 different customers or 2 the same.

The problem is, when I for example select the 2nd or 3rd checkbox it won’t show me which order ID or customer ID I selected, only if I select the 1st checkbox.

Thank you in advance.

[code=php]
if(!empty($_POST[‘action’]))
{

$value = ’empty’;
$i = 1;
while(isset($_POST[‘klant_id’.$i]))
{

if($value == “empty”)
{
$value = $_POST[‘klant_id’.$i];
}

if($_POST[‘klant_id’.$i] != $value )
{
die(“<br><br>It is not possbile to raise an invoice for different customers.”);
}

echo “Customer ID: ” . $_POST[‘klant_id’.$i] . ” Order ID: ” . $_POST[‘order_id’.$i] . “<br>”;

$i++;
}
echo “<br><br>SUCCES!!<br>”;
}
?>
[/code]

[CODE]
[COLOR=”red”]$i = 1;
while($dbinfo = mysql_fetch_assoc($res)) { [/COLOR]

<input type=”checkbox” name=”klant_id[COLOR=”Red”]<?=$i;?>[/COLOR]” value=”[COLOR=”red”]<?=$dbinfo[‘klant_id’];?>[/COLOR]” />
<input type=”hidden” name=”order_id<[COLOR=”red”]?=$i;?>[/COLOR]” value=”[COLOR=”red”]<?=$dbinfo[‘order_id’]?>[/COLOR]”>

[COLOR=”Red”]<?php $i++; }?>[/COLOR]
[/CODE]

to post a comment
PHP

1 Comments(s)

Copy linkTweet thisAlerts:
@pjouwsmaauthorApr 30.2010 — Sorry for the trouble, I think I already solved it.

[code=php]
<?php
$i = 1;
foreach($_POST['order_id'] as $id => $order_id)
{
$sql = "SELECT * FROM order WHERE order_id = '".$order_id."' AND klant_id = '".$_POST['klant_id'][$i]."'";
$res = mysql_query($sql) or die (mysql_error());
$row = mysql_fetch_array($res);

if($row['klant_id'] != $_POST['klant_id'][$i--]) { die("You selected 2 different customers"); }


//echo "Order ID: " . $row['order_id'] . " Klant ID: " . $row['klant_id'] . "<br>";
$i++;
}
?>
[/code]


[CODE]
[COLOR="Red"]
<?php
$order_sql = "SELECT * FROM order ORDER BY gefactureerd ASC, order_id ASC";
$order_res = mysql_query($order_sql);

$i = 1;
while($dbinfo = mysql_fetch_assoc($order_res)) {
?>
[/COLOR]

<input type="checkbox" name="order_id[[COLOR="Red"]<?=$i;?>[/COLOR]]" value="[COLOR="red"]<?=$dbinfo['order_id'];?>[/COLOR]" />
<input type="hidden" name="klant_id[[COLOR="red"]<?=$i;?>[/COLOR]]" value="[COLOR="red"]<?=$dbinfo['klant_id']?>[/COLOR]">

[COLOR="red"]<?php $i++; }?> [/COLOR]

[/CODE]
×

Success!

Help @pjouwsma spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.28,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...