I have a friend with a dinner and he wants to take his iphone and add up how many drinks are being had by each specific person at the bar and store them with date stamps while adding how many drinks they have had total in the life of their account. How do I create form for this, with the add +1 button instead of typing a number?

<form action="store_table.php" method="post" >

<p><b>Person Name</b></br>
<input type="text" name"user" size="10" maxlength="2"/></p>


<!--Is this right?-->

<p><b>How Many Drinks?</b></br>
<input type="button" name"drinks" size="10" value="+1"/></p>

<!--If I hit the button twice will I get a value of 2-->

<p><b>Done</b></br>
<input type="submit" name"Submit" vaule="Submit"/></p>
<!--Is this right?-->

<p><b>How Many Drinks?</b></br>
<input type="button" name"drinks" size="10" value="+1"/></p>

<!--If I hit the button twice will I get a value of 2-->

If adding value=". 1" on a type="radio" can results in $drinks= $_REQUEST

I don't want a bunch of radios and then to just add them all together on the store_table.php

Member Avatar for diafol

If it's just for your friend, use ajax.
have buttons with guests names on them. Every time you press a button their total is incremented (round trip to server).

Like this:


be an idea to have a neg button as well in case of errors.

Obviously, you'd make it a lot prettier, with maybe the name followed by total and then + and - buttons.
Should be simple enough. Use an event handler (using 'this') as opposed to individual onclick attributes.

Member Avatar for diafol

Anyway, here's some js for a js-only sol wrt functionality. Any js guys out there - don't laugh, I only do js once a year!

<?php
	$guest = array("Allan Martin","John Bevan","Phil Bennett","Gareth Edwards");

?>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
<style>
button{
	width: 30px;
}
.name{
	width: 200px;
	float:left;	
}
.total{
	width: 30px;
	color: red;	
	float: left;
}
</style>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.6.2/jquery.min.js#"></script>
<script>
	$(document).ready(function() {
		function doChange(id,action){
			var no = parseInt($('#' + id).html());
			if(action == 'add'){
			  no += 1;
			}else if(no > 0){
			  no -= 1;		
			}
			$('#' + id).html(no);
		}
        $("button").click(function(){
			var id = $(this).siblings(".total").attr('name');
			var action = $(this).attr('class');
			doChange(id,action);
		});
    });
</script>
</head>

<body>
<?php
foreach($guest as $id => $name){
  echo "<div><div class=\"name\">$name</div><div class=\"total\" id=\"$id\" name=\"$id\">0</div><button class=\"add\">+</button><button class=\"take\">-</button></div>";	
}


?>
</body>
</html>

Yeah I like the Ajax idea a whole lot, but there might be a total of 400 users. That could be hard to find. I am guessing it would be best to gather user name and submit... then apply drinks and submit

Would the onclick handle addition. That could be much better than adding radio types.

I'll give the js a try later tonight, thanks!

wow the js was great idea! Thanks!

what if

<?php
	$guest = array("small","medium","large");

?>

How can you echo the totals of those three and then submit them to a database

function person_drinks('person'){
      INSERT INTO person
             (person, drinks)
        VALUE($person, $newdrinks)
}

how to add current drinks to new drinks.

Bill had 22 this year

had 2 tonight

now has $newtotal

add to Bill in database

Member Avatar for diafol

Hmm, you've moved the goalposts. You originally suggested that you needed a simple tally for drinks ordered.

For 400 guests, you just start typing the name into a text box and have a div (with scrollbar). As you change the textbox, the scrollbar moves to the right place OR filters the list. Reasoinably easy.

You have a choice wrt updating DB.

You can do it on every order, so that updating visible total only happens after DB update, or you can just update ONCE at the end of the night for everybody.

Ajax is reasonably fast, especially if you're the only one using the site, but even so, you might hit a bit of a roadblock. taptaptap will probably throw a wobbly.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.