how to match user selected item with their respective quantity and size

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • kang jia
    New Member
    • Jun 2007
    • 88

    how to match user selected item with their respective quantity and size

    hi
    i am doing shopping online, i will let user choose their prodcut in the first page and then when they click" order" button, they will be redirected to do_addcart.php. i will insert their orders into "orders" table and retrieve them back and ask user to select their respective quantity and size. i have used Javascript validation:

    the code is below:
    [CODE=javascript] <script language="JavaS cript">

    <!--

    function validate_form ( )
    {
    valid = true;
    alert (document.Lform .quantity.selec tedIndex);
    if ( document.Lform. quantity.select edIndex == 0 )
    {
    alert ( "Please select your quantity!" );
    Lform.quantity. focus();
    valid = false;
    }
    else if ( document.Lform. size.selectedIn dex == 0 )
    {
    alert ( "Please select your size!" );
    Lform.size.focu s();
    valid = false;
    }
    return valid;
    }
    //-->
    </script>[/CODE]

    However, i don;t know how to correspond respective product with their respective choosen quantity and size.

    the following is my current coding,
    [CODE=php] <?php
    foreach ($_POST as $key => $value) {
    echo "key: ".$key.", value: ".$value."<br>" ;
    $sql = "INSERT INTO orders (imageid, userid, time) VALUES ('$key', '$userid', '$date')";
    mysql_query($sq l);
    }

    echo "Please select your size and quantity for purchase:";
    echo "<table border = '1'>";
    echo "<tr>";
    echo "<td>Title";
    echo "<td>Brand";
    echo "<td>Price";
    echo "<td>Size";
    echo "<td>Quantity";
    echo "</tr>";
    $sql2="SELECT imageid FROM orders";
    $result=mysql_q uery($sql2);
    while($row = mysql_fetch_arr ay($result)) {
    echo "<br>";
    $sql3="SELECT brand, price, title FROM ladies WHERE id=".$row['imageid'];
    $ImageResult = mysql_query($sq l3);
    $ImageDetail = mysql_fetch_arr ay($ImageResult );
    echo "<tr>";
    echo "<td>".$ImageDe tail['title']."";
    echo "<td>".$ImageDe tail['brand']."";
    echo "<td>".$ImageDe tail['price']."";
    echo"<td>";

    echo"
    <select id='size' name='size' tabindex='11'>
    <option value='0'>---
    <option value='1' >S
    <option value='2'>M
    <option value='3'>L
    <option value='4'>XL
    </select>
    </td>";
    //echo" ";


    echo"
    <td>
    <select id='NO' name='quantity' tabindex='11'>
    <option value='0'>---
    <option value='1' >1
    <option value='2'>2
    <option value='3'>3
    <option value='4'>4
    <option value='5'>5
    <option value='6'>6
    <option value='7'>7
    <option value='8'>8
    <option value='9'>9
    <option value='10'>10
    </select>
    </td>";
    echo "</tr>";
    }
    echo "</table>";
    echo "<input type = 'submit' value = 'order'>";
    ?>[/CODE]

    anyone can help me with this, thank you very much. it is bit urgent as the project deadline is near.



    Originally posted by Ajaxrand
    Please enclose your coding with [code] tags
    [Please Find how!]
  • ak1dnar
    Recognized Expert Top Contributor
    • Jan 2007
    • 1584

    #2
    Moving Thread from PHP Articles....

    Post your question in a relevant forum
    Make sure you are not posting in an Articles section

    Comment

    • ak1dnar
      Recognized Expert Top Contributor
      • Jan 2007
      • 1584

      #3
      I can't imagine the way you have used to enter the records from your first page to this php Hope its working fine.

      This is not the correct way to do the thing.First Let me know, is there any Relation ship between ORDERS table and LADIES (Strange ha :) )Table.

      Comment

      • kang jia
        New Member
        • Jun 2007
        • 88

        #4
        Originally posted by ajaxrand
        I can't imagine the way you have used to enter the records from your first page to this php Hope its working fine.

        This is not the correct way to do the thing.First Let me know, is there any Relation ship between ORDERS table and LADIES (Strange ha :) )Table.


        hi

        Orders and Ladies table is interrelated, i will insert whatever users purchases into orders table and there is imageid ( which is foreign key to Ladies table) and userid, so i will know which user choosed which item from imageid. then i use this imageid to retrieve back the value in ladies table.

        the code in the first page is like this

        [code=PHP]:

        <?ob_start();
        session_start() ; ?>
        <html>
        <head>
        <link rel="stylesheet " type="text/css" href="shop.css" /><div id="h">Ladies' Apparels</div>

        </head>
        <body>
        <div id="leftcol" >

        <?php
        //session_start() does not create new session, but identifies same session from do_login.php
        require("db.php ");
        require("curren cy.php");

        $cur = new currency();
        $arr = $cur->get_all_curren cies();
        $currency=$_POS T['currency'];
        $_SESSION['currency']=$currency;
        mysql_connect(M ACHINE, USER, '');
        mysql_select_db (DBNAME);

        // PLEASE CHANGE ACCORDINGLY
        $uploaddir = "images/"; //folder to upload actual images
        $thumbdir = "thumbnails/"; //folder to upload thumbnails

        //Obtaining session variables (From do_login.php)
        $uname = $_SESSION['username'];
        $pwd =$_SESSION['passw'];
        $role = $_SESSION['role'];
        $userid=$_SESSI ON['userid'];

        if (isset($_SESSIO N['username'])) {
        echo "<b>Welcome ". $uname."</b><br>Your <a href = 'cart.php'>Shop ping Cart</a>"; //print welcome mesage
        }

        $sel = "select distinct brand from ladies order by title asc";
        $res = mysql_query($se l);
        echo"<table border='1' cellspacing='10 ' width='50' height='900' align='left'><t d>";

        echo"<img src='file:///C|/xampp-win32-1.5.3a/xampp/htdocs/fyp/online_shop/pic/field.jpg' width='150' height='80' align='center'> <br>";
        echo "<ul>";
        echo "<br><li><h 4><a href=index1.php >All brands</a></h4></li><br>";
        while($rec = mysql_fetch_arr ay($res)){
        $name = $rec['brand'];
        echo "<h4><a href = index1.php?name =".$name.">".$n ame."</a></h4>";
        }
        echo "</ul>";


        //Adding links if logged in or logged out
        echo "<br>";
        if(isset($uname )){ //if user logged in ; log out
        if($role =="admin"){
        //echo "<a href=uploadform .php>Upload Images</a>";
        echo"<a href=uploadform .html>Upload Images</a>";
        echo "<br>";

        }
        echo "<br>";
        echo "<a href=do_logout. php>Log Out</a>";
        echo"<form action='index1. php' method='POST'>" ;

        echo "<select name = 'currency'>";

        foreach ($arr as $key=>$value)
        {

        echo "<option value ='".$key."'>".$ value."</option>\n";

        }

        echo "</select><br>";
        echo "<input type = 'submit' value = 'convert'>";
        echo "</form>";

        $cal = $cur->rateFromSGD($c urrency);
        $look = $cur->lookup($curren cy);


        echo "Currently you are using: ".$look;
        echo"<br>";
        echo "The exchange rate is ".$cal;

        }

        else{ //else: log in

        echo "<a href = login.html>Log In</a><br>";
        echo "<a href = signupform.php> Sign Up</a><br>";

        }
        echo"<img src='file:///C|/xampp-win32-1.5.3a/xampp/htdocs/fyp/online_shop/pic/logo1.jpg' width='150' height='80'><br ><br>";
        echo"<img src='file:///C|/xampp-win32-1.5.3a/xampp/htdocs/fyp/online_shop/pic/logo2.jpg' width='150' height='80'><br ><br>";
        echo"<img src='file:///C|/xampp-win32-1.5.3a/xampp/htdocs/fyp/online_shop/pic/callaway.jpg' width='150' height='80'><br ><br>";
        echo"<img src='file:///C|/xampp-win32-1.5.3a/xampp/htdocs/fyp/online_shop/pic/logo4.jpg' width='150' height='80'><br ><br>";
        echo"<img src='file:///C|/xampp-win32-1.5.3a/xampp/htdocs/fyp/online_shop/pic/logo5.jpg' width='150' height='80'><br ><br>
        <img src='file:///C|/xampp-win32-1.5.3a/xampp/htdocs/fyp/online_shop/pic/logo6.jpg' width='150' height='80'><br ><br>
        <img src='file:///C|/xampp-win32-1.5.3a/xampp/htdocs/fyp/online_shop/pic/logo7.jpg' width='150' height='80'><br ><br>
        <img src='file:///C|/xampp-win32-1.5.3a/xampp/htdocs/fyp/online_shop/pic/logo8.jpg' width='150' height='80'><br ><br>
        <img src='file:///C|/xampp-win32-1.5.3a/xampp/htdocs/fyp/online_shop/pic/logo9.jpg' width='150' height='80'><br ><br>
        <img src='file:///C|/xampp-win32-1.5.3a/xampp/htdocs/fyp/online_shop/pic/logo10.jpg' width='150' height='80'><br ><br>
        <img src='file:///C|/xampp-win32-1.5.3a/xampp/htdocs/fyp/online_shop/pic/logo11.jpg' width='150' height='80'><br ><br>
        <img src='file:///C|/xampp-win32-1.5.3a/xampp/htdocs/fyp/online_shop/pic/logo12.jpg' width='150' height='80'><br ><br>";
        echo"</td></table>";

        ?>
        </div>

        <div id="maincol">
        <form name = "form" method = "POST" action = "do_addcart.php " onSubmit = 'return validate_form ();'>
        <?php
        $getName = $_GET['name'];

        if (isset($getName )){
        $selPaint = "SELECT * from ladies where brand ='".$getName."' ";

        }
        else{
        $selPaint = "SELECT * from ladies";
        }

        $execPaint = mysql_query($se lPaint);
        while($thisArt = mysql_fetch_arr ay($execPaint)) {

        $fName = $thisArt['filename'];
        $id = $thisArt['id'];
        $_SESSION['id']=$id;

        //echo "<input type='hidden' name='vin' value=$id>";

        echo"<table bgcolor='#FFFFF F' border='1' width='570' height='200' cellspacing='5' >";
        $title=$thisArt['title'];
        echo "<h3><td>".$tit le."</h3>";

        $text=wordwrap( $title,2,"<br />\n");

        echo "<a href =".$uploaddir.$ fName.">";
        echo "<img src=".$thumbdir ."thumb_".$fNam e."></a><br>";

        $price=$thisArt['price'];
        echo "<td><br><br><b r>";
        $Des = "<h4>".$thi sArt['description']."</h4><br>";
        $text1=wordwrap ($Des,60,"<br />\n");
        echo"<h3>".$tex t1."</h3></td><br>";
        /*if($role =="admin"){
        echo "<td><a href=\"do_delet e.php?id=".$id. "\">Delete</a></td>";
        echo "<td><a href=\"updateco ntact.php?id=". $id."\">Update</a></td>";

        }*/
        echo"</table>";
        echo "<BR>";

        if (isset($_SESSIO N['userid'])) {

        if($role =="admin"){
        //echo"&nbsp;&nbs p;&nbsp;&nbsp;& nbsp;&nbsp;&nbs p;&nbsp;&nbsp;& nbsp;&nbsp;&nbs p;";
        echo "<a href=\"do_delet e.php?id=".$id. "\">Delete</a>";
        echo "&nbsp;&nbs p;";
        echo "<a href=\"update.p hp?id=".$id."\" >Update</a>";
        echo "<br>";
        echo "<br>";
        }
        $rprice=round($ price,2);
        if(isset($curre ncy)){
        $asd = $price*$cal;
        $round=round($a sd,2);
        echo"<table>";
        echo"<tr>";
        echo"<td>";
        echo "<input type = 'checkbox' value = '1' name = '".$id."'>Bu y this poster. Currency: ".$look.". Price = $". $round;
        }
        else{
        echo "<input type = 'checkbox' value = '1' name = '".$id."'>Bu y this poster. Price = $ S.G ".$rprice;
        echo "<br>";

        }

        }

        }


        if (isset($_SESSIO N['userid'])) {
        echo "<br>";
        echo "<br>";
        echo "<input type = 'submit' value = 'order'>";
        echo "<br>";
        echo "<br>";
        }
        //echo"<a href=.php>go back</a><br>";
        //echo "<input type='hidden' name='vin' value=$id>";
        ?>


        </form>
        </div>
        </body>
        </html>

        [/code]



        the code in do_addcart.php is in the following:

        [code=PHP]:
        <?
        ob_start();
        session_start() ;
        ?>
        <html>
        <head>
        <link rel="stylesheet " type="text/css" href="shop.css" /><div id="h">Ladies' Apparels</div>
        <script language="JavaS cript">

        <!--

        function validate_form ( )
        {
        valid = true;
        alert (document.Lform .$quantity.sele ctedIndex);
        if ( document.Lform. $quantity.selec tedIndex == 0 )
        {
        alert ( "Please select your quantity!" );
        Lform.$quantity .focus();
        valid = false;
        }
        else if ( document.Lform. $size.selectedI ndex == 0 )
        {
        alert ( "Please select your size!" );
        Lform.$size.foc us();
        valid = false;
        }
        return valid;
        }
        //-->
        </script>
        </head>
        <body>
        <div id="maincol">
        <form name = "Lform" method = "POST" action = "do_addcart.php " onSubmit = 'return validate_form ();'>
        <?
        ob_start();
        session_start() ;

        require("db.php ");

        mysql_connect(M ACHINE, USER, '');
        mysql_select_db (DBNAME);


        $userid = $_SESSION['userid'];

        $date=date("D j-M-Y G:i:s");
        echo $date;
        echo"<BR>";

        foreach ($_POST as $key => $value) {
        echo "key: ".$key.", value: ".$value."<br>" ;
        $sql = "INSERT INTO orders (imageid, userid, time) VALUES ('$key', '$userid', '$date')";
        mysql_query($sq l);
        }

        echo "Please select your size and quantity for purchase:";
        echo "<table border = '1'>";
        echo "<tr>";
        echo "<td><b>Tit le</b></td>";
        echo "<td><b>Bra nd</b></td>";
        echo "<td><b>Pri ce</b></td>";
        echo "<td><b>Siz e</b></td>";
        echo "<td><b>Quantit y</b></td>";
        echo "</tr>";
        $sql2="SELECT imageid FROM orders";
        $result=mysql_q uery($sql2);
        while($row = mysql_fetch_arr ay($result)) {
        echo "<br>";
        $sql3="SELECT brand, price, title FROM ladies WHERE id=".$row['imageid'];
        $ImageResult = mysql_query($sq l3);
        $ImageDetail = mysql_fetch_arr ay($ImageResult );
        echo "<tr>";
        echo "<td>".$ImageDe tail['title']."</td>";
        echo "<td>".$ImageDe tail['brand']."</td>";
        echo "<td>".$ImageDe tail['price']."</td>";
        echo"<td>";
        echo"
        <select id='size' name='$size' tabindex='11'>
        <option value='0'>---</option>
        <option value='1' >S</option>
        <option value='2'>M</option>
        <option value='3'>L</option>
        <option value='4'>XL</option>
        </select>
        </td>";
        //echo"&nbsp;&nbs p;&nbsp;&nbsp;" ;
        $quantity=0;
        $quantity=$quan tity+1;

        echo"
        <td>
        <select id='NO' name='$quantity ' tabindex='11'>
        <option value='0'>---</option>
        <option value='1' >1</option>
        <option value='2'>2</option>
        <option value='3'>3</option>
        <option value='4'>4</option>
        <option value='5'>5</option>
        <option value='6'>6</option>
        <option value='7'>7</option>
        <option value='8'>8</option>
        <option value='9'>9</option>
        <option value='10'>10</option>
        </select>
        </td>";
        echo "</tr>";
        }
        echo "</table>";


        //header('Refresh : 3; url=cart.php');
        //echo "<meta http-equiv='refresh' content='5;url= http://google.com'>";
        echo "<input type = 'submit' value = 'order'>";
        echo"<BR>";
        echo "Your order is being processed, you will be directed to your shopping cart soon";

        ?>
        </body>
        </html>

        [/code]

        i would like users to choose the items's respective quantity and size, but i don't know how to know which quantity and size is belong to which item. i think my naming may have problem since i all use "quantity" and "size" for every item. but i don't know how to sovle it. i have no clue of it. can help me with it. thanks in advance

        Comment

        • ak1dnar
          Recognized Expert Top Contributor
          • Jan 2007
          • 1584

          #5
          There are lots of Errors in your script.

          • You are trying to print $quantity, $size inside the HTML(Javascript ) code
            Note that PHP is executing in server side,not in the client side.if you need to print server side php varibles inside html coding, you may replace
          [CODE=javascript]
          document.Lform. $quantity.selec tedIndex == 0
          [/CODE]

          with this

          [CODE=php]
          document.Lform. <?php $quantity ?>.selectedInde x == 0
          [/CODE]

          And Under those list menus why is that name attribute is set to $quantity,$size . From where it is coming from?
          are you planing to set the same size and quantity for all purchased item(what are those item really).

          Comment

          • kang jia
            New Member
            • Jun 2007
            • 88

            #6
            Originally posted by ajaxrand
            There are lots of Errors in your script.

            • You are trying to print $quantity, $size inside the HTML(Javascript ) code
              Note that PHP is executing in server side,not in the client side.if you need to print server side php varibles inside html coding, you may replace
            [CODE=javascript]
            document.Lform. $quantity.selec tedIndex == 0
            [/CODE]

            with this

            [CODE=php]
            document.Lform. <?php $quantity ?>.selectedInde x == 0
            [/CODE]

            And Under those list menus why is that name attribute is set to $quantity,$size . From where it is coming from?
            are you planing to set the same size and quantity for all purchased item(what are those item really).


            hi, in fact i was writiing a loop, but i think i delete it befoer i post, originally, i wrtie
            [code=PHP]
            $quantity=0;
            $quantity=$quan tity+1; // do the same for $size;
            [/code]
            i do in this is to let the drop down list of quantity and size have differe name, so that i may know which item user purchased according to which quantity and size name; something like quantity1=3, quantity2=5,etc .but finally i can not achieve it, i have only this kind of concept.is this concept correct?

            in fact, i would like to know the quantity and size they choosed accorrding to the different items they buy and it is a must for them to select quantity and size from drop down list for every item they buy.

            i don;t know how should i write the code so that i will know which quantity and size user selected is corresponding to which item they buy and there is also a validation so that user will not forget to select their item's quantity and size.

            can help me with these part of the code, thank you very much. i am very frustrated as the project deadline is near. thank you very much for your kind help :)

            Comment

            • ak1dnar
              Recognized Expert Top Contributor
              • Jan 2007
              • 1584

              #7
              Can I see the Table structure first.Then I might be able to help.

              Or else go for a re-structuring you tables and Apps by your self.

              Example:
              • From Products table list all the products to page(s) with the unique product_id
                EX: 1001,1002,1003, 1004,....,n
              • Insert the selected products to orders table by sending the product_id to the Orders table
                Ex: user select the product 1001 and 1004, then insert them to orders table.
              • Once you came to this stage.(update shopping cart)
                User can Insert Number of Items and size for 1001 and 1004
              You can put those size and Quantity in side the while loop and display the corresponding list menus for both selected products.
              Ex:

              1001 - size_list_menu - qty_list_menu
              1004 - size_list_menu - qty_list_menu

              [You can display the product Image/Name instead of Product_id to the User]
              Once user select the size and Qty update them to Orders Table again.
              So now for all the purchased item(s) you have.

              ProductNumber
              Size
              Qty

              That's it, Then proceed with your Payment gateway.

              Comment

              • kang jia
                New Member
                • Jun 2007
                • 88

                #8
                Originally posted by ajaxrand
                Can I see the Table structure first.Then I might be able to help.

                Or else go for a re-structuring you tables and Apps by your self.

                Example:
                • From Products table list all the products to page(s) with the unique product_id
                  EX: 1001,1002,1003, 1004,....,n
                • Insert the selected products to orders table by sending the product_id to the Orders table
                  Ex: user select the product 1001 and 1004, then insert them to orders table.
                • Once you came to this stage.(update shopping cart)
                  User can Insert Number of Items and size for 1001 and 1004
                You can put those size and Quantity in side the while loop and display the corresponding list menus for both selected products.
                Ex:

                1001 - size_list_menu - qty_list_menu
                1004 - size_list_menu - qty_list_menu

                [You can display the product Image/Name instead of Product_id to the User]
                Once user select the size and Qty update them to Orders Table again.
                So now for all the purchased item(s) you have.

                ProductNumber
                Size
                Qty

                That's it, Then proceed with your Payment gateway.

                i think i have the same concept as you when i am doing this, but my problem is how should i validate user's selection of their selected item's size and quantity as users may forget to choose some of them. my validation now is
                Code:
                <?
                	ob_start();
                	session_start();
                ?>
                <html>
                <head>
                <link rel="stylesheet" type="text/css" href="shop.css" /><div id="h">Ladies' Apparels</div>
                <script language="JavaScript">
                 
                <!--
                 
                function validate_form ( )
                {
                valid = true;
                alert (document.Lform.quantity.selectedIndex);
                if ( document.Lform.quantity.selectedIndex == 0 )
                {
                alert ( "Please select your quantity!" );
                				Lform.quantity.focus();
                valid = false;
                }
                	else if ( document.Lform.size.selectedIndex == 0 )
                {
                alert ( "Please select your size!" );
                				Lform.size.focus();
                valid = false;
                }
                			return valid;
                }
                 
                </script>
                </head>
                <body>
                <?
                	ob_start();
                	session_start();
                 
                	require("db.php");
                 
                	mysql_connect(MACHINE, USER, '');
                	mysql_select_db(DBNAME);
                 
                 
                	$userid = $_SESSION['userid'];
                 
                	$date=date("D j-M-Y G:i:s");
                	echo $date;
                	echo"<BR>";
                 
                foreach ($_POST as $key => $value) {
                	echo "key: ".$key.", value: ".$value."<br>";
                		$sql = "INSERT INTO orders (imageid, userid, time) VALUES ('$key', '$userid', '$date')";
                		mysql_query($sql); 
                	}
                $sql2="SELECT imageid FROM orders";
                $result=mysql_query($sql2);
                while($row = mysql_fetch_array($result)) {
                				echo "<br>";
                				$id=$row['imageid'];
                				$_SESSION['id1']=$id;
                				$sql3="SELECT brand, price, title FROM ladies WHERE id=".$row['imageid'];
                				$ImageResult = mysql_query($sql3);
                				$ImageDetail = mysql_fetch_array($ImageResult);
                				echo "<tr>";
                				echo "<td>".$ImageDetail['title']."</td>";
                				echo "<td>".$ImageDetail['brand']."</td>";
                				echo "<td>".$ImageDetail['price']."</td>";
                				echo"<td>";
                	echo"
                			<select id='size' name='size' tabindex='11'>
                							<option value='0'>---</option>
                							<option value='1' >S</option>
                							<option value='2'>M</option>
                							<option value='3'>L</option>
                							<option value='4'>XL</option>
                					</select>
                					</td>"; 	
                	//echo"&nbsp;&nbsp;&nbsp;&nbsp;";	
                 
                 
                	echo"
                		<td>
                			<select id='NO' name='quantity' tabindex='11'>
                							<option value='0'>---</option>
                							<option value='1' >1</option>
                							<option value='2'>2</option>
                							<option value='3'>3</option>
                							<option value='4'>4</option>
                							<option value='5'>5</option>
                							<option value='6'>6</option>
                							<option value='7'>7</option>
                							<option value='8'>8</option>
                							<option value='9'>9</option>
                							<option value='10'>10</option>
                					</select>
                					</td>"; 
                ?>
                </body>
                </html>
                however, it seems does not work at all, i think because of the naming problem. as every item is using the name of 'quantity' and 'size', so the program don;t know which quantity and size choosen is belong to which item. so how should i sovle this? this is the main problem. thanks :)

                PS. my product id is atom increment, the other fields are brand, price,descripti on,etc. in my orders table, i got product id as foreign key, userid as foreign key. the rest of field is time, quantity, size.

                thank you very much for your kind help. this is a bit urgent as my project's deadline is very near. if possible, please reply me ASAP. thanks:)

                Comment

                • ak1dnar
                  Recognized Expert Top Contributor
                  • Jan 2007
                  • 1584

                  #9
                  Since this is a shopping cart you can set some default size and Quantity for a selected item always.
                  Ex:
                  Qty always set to 1
                  Size set to S

                  For a Customer do we need to display 0 s or blanks for products, I dnt think so.Then no need of validation at all.

                  Still if you expecting validation just give me some times.
                  Thanks!
                  -Ajaxrand

                  Comment

                  • kang jia
                    New Member
                    • Jun 2007
                    • 88

                    #10
                    Originally posted by ajaxrand
                    Since this is a shopping cart you can set some default size and Quantity for a selected item always.
                    Ex:
                    Qty always set to 1
                    Size set to S

                    For a Customer do we need to display 0 s or blanks for products, I dnt think so.Then no need of validation at all.

                    Still if you expecting validation just give me some times.
                    Thanks!
                    -Ajaxrand

                    the default is all 1, but my supervisor don;t think it is practical in real life to let everyone just buy one and they should be able to select the size they wear. that is why i have to do the validation of size and quantity for each item they buy.

                    i have to insert their size and quanity for the respective item in database, so i have to know which size and quantity is belong to which item.

                    sure, i will wait for your kind reply. thanks. :)

                    Comment

                    • ak1dnar
                      Recognized Expert Top Contributor
                      • Jan 2007
                      • 1584

                      #11
                      Originally posted by kang jia
                      the default is all 1, but my supervisor don;t think it is practical in real life to let everyone just buy one and they should be able to select the size they wear. that is why i have to do the validation of size and quantity for each item they buy.

                      i have to insert their size and quantity for the respective item in database, so i have to know which size and quantity is belong to which item.

                      sure, i will wait for your kind reply. thanks. :)
                      Just Listen to me again,

                      Why Customer(s) comes to e-commerce sites. to Buy isn't it.
                      Do they ever purchasing "0" items. NO.
                      Its should be greater than 1 always.
                      Then Size, As I know you are going to display S,M,L,XL with your products.
                      So can't we set one of them by default. If User don't want that Size say XL is set by default and he needs L so he will do it.

                      However get in touch with your SUPERvisor :)

                      [code=php]
                      <?php
                      $con = mysql_connect(' localhost', 'root', 'dba') or die ("Could not connect to the Database");
                      mysql_select_db ('test', $con) or die (mysql_error()) ;
                      $query1 = 'Select p_id from products';
                      $result1 = mysql_query($qu ery1);
                      $query2 = 'Select p_id from products';
                      $result2 = mysql_query($qu ery2);
                      ?>
                      <html>
                      <head>
                      <script language="JavaS cript" type="text/javascript">
                      function menuChk(){
                      <?php
                      while ($row1 = mysql_fetch_arr ay($result1))
                      {
                      ?>
                      var Str<?=$row1['p_id']?> = document.formOb j.Qty<?=$row1['p_id']?>.selectedInde x;
                      if (Str<?=$row1['p_id']?> == 0){
                      alert("Please select the Quantity!");
                      document.formOb j.Qty<?=$row1['p_id']?>.focus();
                      return false;
                      }
                      <?
                      }
                      ?>
                      }
                      </script>
                      </head>
                      <body>
                      <form id="formObj" name="formObj" method="post" action="server. php" onsubmit="retur n menuChk();">
                      <?php
                      while ($row2 = mysql_fetch_arr ay($result2))
                      {
                      ?>
                      <select name="Qty<?=$ro w2['p_id']?>">
                      <option value="0">0</option>
                      <option value="1">1</option>
                      <option value="2">2</option>
                      </select>
                      <br />
                      <?php
                      }
                      ?>
                      <input name="" type="submit" />
                      </form>
                      </body>
                      </html>

                      [/code]

                      This will print somting like this dynamically.

                      [code=html]
                      <html>
                      <head>
                      <script language="JavaS cript" type="text/javascript">
                      function menuChk(){
                      var Str143 = document.formOb j.Qty143.select edIndex;
                      if (Str143 == 0){
                      alert("Please select the Quantity!");
                      document.formOb j.Qty143.focus( );
                      return false;
                      }
                      var Str144 = document.formOb j.Qty144.select edIndex;
                      if (Str144 == 0){
                      alert("Please select the Quantity!");
                      document.formOb j.Qty144.focus( );
                      return false;
                      }
                      var Str145 = document.formOb j.Qty145.select edIndex;
                      if (Str145 == 0){
                      alert("Please select the Quantity!");
                      document.formOb j.Qty145.focus( );
                      return false;
                      }
                      var Str146 = document.formOb j.Qty146.select edIndex;
                      if (Str146 == 0){
                      alert("Please select the Quantity!");
                      document.formOb j.Qty146.focus( );
                      return false;
                      }
                      var Str147 = document.formOb j.Qty147.select edIndex;
                      if (Str147 == 0){
                      alert("Please select the Quantity!");
                      document.formOb j.Qty147.focus( );
                      return false;
                      }
                      var Str148 = document.formOb j.Qty148.select edIndex;
                      if (Str148 == 0){
                      alert("Please select the Quantity!");
                      document.formOb j.Qty148.focus( );
                      return false;
                      }
                      }
                      </script>
                      </head>
                      <body>
                      <form id="formObj" name="formObj" method="post" action="server. php" onsubmit="retur n menuChk();">
                      <select name="Qty143">
                      <option value="0">0</option>
                      <option value="1">1</option>
                      <option value="2">2</option>
                      </select>
                      <br />
                      <select name="Qty144">
                      <option value="0">0</option>
                      <option value="1">1</option>
                      <option value="2">2</option>
                      </select>
                      <br />
                      <select name="Qty145">
                      <option value="0">0</option>
                      <option value="1">1</option>
                      <option value="2">2</option>
                      </select>
                      <br />
                      <select name="Qty146">
                      <option value="0">0</option>
                      <option value="1">1</option>
                      <option value="2">2</option>
                      </select>
                      <br />
                      <select name="Qty147">
                      <option value="0">0</option>
                      <option value="1">1</option>
                      <option value="2">2</option>
                      </select>
                      <br />
                      <select name="Qty148">
                      <option value="0">0</option>
                      <option value="1">1</option>
                      <option value="2">2</option>
                      </select>
                      <br />
                      <input name="" type="submit" />
                      </form>
                      </body>
                      </html>

                      [/code]

                      Comment

                      • kang jia
                        New Member
                        • Jun 2007
                        • 88

                        #12
                        i do think what you said previously is very true , we can just set default value ma, later user want to change, they will change, i will validate my reasons with my supervisor, thanks for your kind help . but if i choose to use the defult one, how should i insert in database.

                        Originally posted by Ajaxrand
                        Remaining section removed from the post,Please read the next thread to find out the reason.
                        Last edited by ak1dnar; Jul 16 '07, 01:31 PM. Reason: Cannot See the post - Too long

                        Comment

                        • ak1dnar
                          Recognized Expert Top Contributor
                          • Jan 2007
                          • 1584

                          #13
                          Sorry I have to delete this post from the thread.

                          Reason:
                          Cannot see the post. its empty.
                          May be its too long.

                          Please Remove the unwanted static contents from your coding and re-post it.

                          Thanks!
                          -Ajaxrand

                          Comment

                          • kang jia
                            New Member
                            • Jun 2007
                            • 88

                            #14
                            Originally posted by ajaxrand
                            Sorry I have to delete this post from the thread.

                            Reason:
                            Cannot see the post. its empty.
                            May be its too long.

                            Please Remove the unwanted static contents from your coding and re-post it.

                            Thanks!
                            -Ajaxrand

                            thanks for your kind help, i just sovled it with my other friends' help, really thanks, you are so nice and kind to help me!

                            Comment

                            • ak1dnar
                              Recognized Expert Top Contributor
                              • Jan 2007
                              • 1584

                              #15
                              Originally posted by kang jia
                              thanks for your kind help, i just sovled it with my other friends' help, really thanks, you are so nice and kind to help me!
                              Glad to hear that !Well done!
                              Come back any time to TSDN.
                              -Ajaxrand

                              Comment

                              Working...