SitePoint Sponsor

User Tag List

Results 1 to 5 of 5
  1. #1
    Visible Ninja bronze trophy
    JeffWalden's Avatar
    Join Date
    Sep 2002
    Location
    Los Angeles
    Posts
    1,709
    Mentioned
    5 Post(s)
    Tagged
    0 Thread(s)

    Smile Best Method Using PHP?

    I need to re-think the setup I am using as it is creating too many problems. Basically, I need to:

    1. Pull products from database (maybe 10, but changes daily) ...
    got this done

    2. Display these products so the user can somehow select them and enter a qty, or possibly select them BY entering a qty ...
    I previously used checkboxes, but it is confusing consumers that they need to tick the box AND type a qty in the textbox, I need to do away with the checkbox

    3. Display all the selected products in an easy to view, printable page ...
    this worked fine in that I used isset to call only the variables with values

    Anyway, my biggest problem is the checkbox thing. Currently, users need to both tick the checkbox to select the product (and pass it along to the next page) and they also need to enter a qty into the textbox. Dr Livingston has been helping me with JavaScript to automatically tick the checkbox when a qty is entered, but that might still not work as the user will possibly have JavaScript disabled.

    Any ideas on how to set this up? The checkbox thing was a bad idea unless I can use some sort of system to validate the checkbox is ticked EVERY time a value other than 0 is entered for the qty textbox.

    Completely open here... just throw em at me!
    TAKE A WALK OUTSIDE YOUR MIND.

  2. #2
    Sultan of Ping jofa's Avatar
    Join Date
    Mar 2002
    Location
    SvÝ■jˇ­
    Posts
    4,080
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Remove the checkboxes and use the values in the textboxes only?
    If qty is <= 0 or not a number, don't add the product

  3. #3
    Visible Ninja bronze trophy
    JeffWalden's Avatar
    Join Date
    Sep 2002
    Location
    Los Angeles
    Posts
    1,709
    Mentioned
    5 Post(s)
    Tagged
    0 Thread(s)
    Thanks jofa, any idea on the code for this? This came up as a possiblity, but I ruled it out as the scripts were just not working for me.

    CheckBox Name = SoupName
    TextBox Names = cup, bowl, mulloy

    This is what I currently have on the printout page:
    PHP Code:
    if(isset($_POST['SoupName'])){

    foreach (
    $SoupName as $i=>$Soup

    echo 
    '<tr>'
    echo 
    '<td><font size=3> ' $Soup '</td>'
    echo 
    '<td><font size=3> ' $cup[$i] . '</td>'
    echo 
    '<td><font size=3> ' $bowl[$i] . '</td>'
    echo 
    '<td><font size=3> ' $mulloy[$i] . '</td>'
    echo 
    '</tr>'
    }

    TAKE A WALK OUTSIDE YOUR MIND.

  4. #4
    Sultan of Ping jofa's Avatar
    Join Date
    Mar 2002
    Location
    SvÝ■jˇ­
    Posts
    4,080
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I was thinking of something like this:
    Code:
    <html>
    	<body>
    <?
    if($_POST["submit"])
    {
    	$names = $_POST["names"];
    	foreach($names as $name)
    	{
    		$qty = $_POST[$name];
    		if(is_numeric($qty) && $qty > 0)
    		{ 
    			echo "$name: $qty<br>";
    		}
    	}
    }
    else
    {
    ?>
    		<form method="post">
    <?
    	for($i = "a"; $i < "f"; $i++)
    	{
    		echo "Qty of $i: 
    			<input type='text' name='$i'>
    			<input type='hidden' name='names[]' value='$i'>
    			<br>";
    	}
    ?>
    			<input type="submit" name="submit" value="OK">
    		</form>
    <?
    }
    ?>
    	</body>
    </html>

  5. #5
    Visible Ninja bronze trophy
    JeffWalden's Avatar
    Join Date
    Sep 2002
    Location
    Los Angeles
    Posts
    1,709
    Mentioned
    5 Post(s)
    Tagged
    0 Thread(s)
    Thanks Jofa! My brain stops working and I needed another kickstart. Everything is working now.

    THANKS AGAIN!
    TAKE A WALK OUTSIDE YOUR MIND.


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •