SitePoint Sponsor

User Tag List

Results 1 to 4 of 4
  1. #1
    SitePoint Enthusiast
    Join Date
    May 2005
    Posts
    44
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Question HELP needed.. about "Dynamic Checkboxes".. anyone knows? Please?

    I have a Purchase requisition system, what it basically do is logging of requested item(s) to be purchased. The second phase after logging is checking if the list of items are available in the database, and if they're, it will generate a Bid Summary screen with the prices and supplier names derived from the database. The user will then see which supplier have the least prices for the items requested.

    The current system that I am having now do the thing but for cases like the requisition have several items that are not available from just 1 supplier, there should be an option to choose from the available suppliers listed (i.e. 17" Monitor from supplier A is cheaper from supplier B and so on)

    There should be a provision whereby user can choose the least priced item among the supplier listed. There is a "bidsummary" table where all the values from bid summary page should be saved. I have done some testing already but unfortunately I couldn't make it work properly like dynamically having a checkbox beside the unit price of an item, so that the user can have an option to choose an item that has a least price among the suppliers listed.

    Can someone please help me on this matter? please? THANK YOU in advance. I have my existing data sctructures, codes and snapshot below.

    Things needed to be done:

    1) Dynamically put a checkbox next to the unit price like shown on the snap shot below.

    2) Dynamically calculate the total of items selected from each suppliers, if no items selected from a supplier, the total should be equal to "0.00"

    3) Transfering the values of the bid summary page to the "bidsummary" table on the database then changing the "IsApproved" field name on the "bidsummary" table to "Yes" when an item price is checked since the default is set to "No".

    Needed Options: when there is no checked items, notice the total


    Needed Options: when item(s) are checked, notice the total


    Current Codes: (with the help of KillerKookie)
    PHP Code:
    <?php 
    include("includes/functions.inc.php"); 
    include(
    "config/db.conf.php"); 



    //To get a list of all possible suppliers. 
    //$supplierArray will be an associative array holding name and the position in $supplierTotalArray. 
    //$supplierTotal will be an associative array holding the totals for the items. 
    $supplierArray = array(); 
    $supplierTotalArray = array(); 
    $getSuppliersSQL "SELECT 
                            DISTINCT items.supplier_name 
                        FROM 
                            ticket, 
                            ticketitems, 
                            items 
                        WHERE 
                            ticket.t_id = ticketitems.t_id AND 
                            ticketitems.ItemName = items.ItemName 
                        ORDER BY 
                            items.supplier_name"

    $getSuppliersResult query($getSuppliersSQL); 

    //Initialise $supplierArray to 0 for all possible suppliers. 
    $supplierTotalPositionCount 0
    while (
    $resultRow mysql_fetch_row($getSuppliersResult)) { 
        
    $supplierName $resultRow[0]; 
        
    $supplierArray{$supplierName} = $supplierTotalPositionCount
        
    $supplierTotalArray[] = 0
        
    $supplierTotalPositionCount++; 
        } 

    //Rendering the table 
    $supplierCount count($supplierArray); 
    ?> 
    <table width="100%" border="0" cellspacing="0" cellpadding="0"> 
        <tr valign="top"> 
            <td>Item Order</td> 
            <td>Item Name</td> 
            <td>Quantity</td> 
            <td colspan="<? echo $supplierCount?>">Supplier / Unit Price</td> 
        </tr> 
        <tr valign="top"> 
            <td>&nbsp;</td> 
            <td>&nbsp;</td> 
            <td>&nbsp;</td> 
    <? 
    $suppliers 
    array_keys($supplierArray); 
    foreach (
    $suppliers As $currentName) { 
        echo 
    '<td>' $currentName '</td>'
        } 
    ?> 
        </tr> 
    <? 

    //To get a list of all possible orders. 
    //$ordersArray will be an associative array holding the order details. 
    //$ordersHTMLArray will be an associative array holding the order HTML. 
    $ordersArray =  array(); 
    $ordersHTMLArray = array(); 
    $getOrdersSQL "SELECT 
                        ticketitems.ItemOrder, 
                        ticketitems.ItemName, 
                        ticketitems.ItemQty 
                    FROM 
                        ticket, 
                        ticketitems 
                    WHERE 
                        ticket.t_id = ticketitems.t_id 
                    ORDER BY 
                        ticketitems.ItemOrder ASC"

    $getOrdersResult query($getOrdersSQL); 

    //Populate $ordersArray with Details. 

    while ($resultRow mysql_fetch_row($getOrdersResult)) { 
        
    $itemOrder $resultRow[0]; 
        
    $itemName $resultRow[1]; 
        
    $itemQuantity $resultRow[2]; 
        
    $ordersArray{$itemName} = array('order' => $itemOrder'name' => $itemName'quantity' => $itemQuantity); 
        } 

    //Get Suppliers for the Items 
    $orders array_keys($ordersArray); 

    foreach (
    $orders As $currentItem) { 
        
    $itemRowSQL "SELECT 
                            items.description, 
                            items.brandname, 
                            items.price, 
                            items.supplier_name 
                        FROM 
                            items 
                        WHERE 
                            items.ItemName = '" 
    $currentItem "' 
                        ORDER BY 
                            items.supplier_name ASC"

        
    $itemRowResult query($itemRowSQL); 

        
    $positionalArray = array(); 
        while (
    $resultRow mysql_fetch_row($itemRowResult)) { 
            
    $itemDescription $resultRow[0]; 
            
    $itemBrand $resultRow[1]; 
            
    $itemPrice $resultRow[2]; 
            
    $itemSupplier $resultRow[3]; 
            
    $supplierColumn $supplierArray[$itemSupplier]; 
            
    $tempArray $ordersArray[$currentItem]; 
            
    $itemOrder $tempArray['order']; 
            
    $itemName $tempArray['name']; 
            
    $itemQuantity $tempArray['quantity']; 
            
    $supplierTotalArray[$supplierColumn] = $supplierTotalArray[$supplierColumn] + ($itemPrice *$itemQuantity); 
            
    $formattedPrice sprintf('%.2f'$itemPrice); 
            
    $positionalArray[$supplierColumn] = '<td>' $formattedPrice '</td>'
            } 
        
    $rowSupplierHTML ''
        for (
    $counter 0$counter $supplierCount$counter++) { 
            if (
    array_key_exists($counter$positionalArray)) 
                
    $rowSupplierHTML .= $positionalArray[$counter]; 
            else 
                
    $rowSupplierHTML .= '<td>&nbsp;</td>'
            } 
        
    $ordersHTMLArray{$itemName} = '<tr><td>' $itemOrder '</td><td>' $itemName '</td><td>' $itemQuantity '</td>' $rowSupplierHTML '</tr>'
        } 

    foreach (
    $ordersHTMLArray As $currentHTML) { 
        echo 
    $currentHTML
        } 

    ?> 

     <tr> 
            <td>&nbsp;</td> 
            <td>&nbsp;</td>
            <td>&nbsp;</td> 
            <td>&nbsp;</td>
            </tr>

        <tr> 
            <td>&nbsp;</td> 
            <td>&nbsp;</td> 
            <td>Total</td> 
    <? 
    foreach ($supplierTotalArray As $currentValue) { 
        
    $formattedTotal sprintf('%.2f'$currentValue); 
        echo 
    '<td>' $formattedTotal '</td>'
        } 
    ?> 
        </tr> 
    </table>
    Table Structures:
    Code:
    CREATE TABLE `bidsummary` (
      `b_id` int(7) unsigned NOT NULL auto_increment,
      `t_id` int(7) unsigned NOT NULL default '0',
      `ItemOrder` int(10) unsigned NOT NULL default '0',
      `ItemName` varchar(255) NOT NULL default '',
      `price` float(10,2) NOT NULL default '0.00',
      `ItemQty` int(10) unsigned NOT NULL default '0',
      `total` float(10,2) NOT NULL default '0.00',
      `supplier_name` varchar(30) NOT NULL default '',
      `IsApproved` set('No','Yes') NOT NULL default 'No',
      PRIMARY KEY  (`b_id`)
    ) ENGINE=MyISAM DEFAULT CHARSET=latin1;
    
    
    
    #
    # Dumping data for table 'bidsummary'
    #
    
    
    
    #
    # Table structure for table 'items'
    #
    
    CREATE TABLE `items` (
      `id` int(10) unsigned NOT NULL auto_increment,
      `groupname` varchar(30) NOT NULL default '',
      `ItemName` varchar(255) NOT NULL default '',
      `description` text NOT NULL,
      `brandname` varchar(30) NOT NULL default '',
      `price` float(10,2) NOT NULL default '0.00',
      `supplier_name` varchar(30) NOT NULL default '',
      `status` varchar(10) NOT NULL default '',
      PRIMARY KEY  (`id`)
    ) ENGINE=MyISAM DEFAULT CHARSET=latin1;
    
    
    
    #
    # Dumping data for table 'items'
    #
    
    INSERT INTO `items` VALUES("1", "Monitors", "Flat Screen", "17\" Monitor blah blah\r\n", "Acer", "573.25", "ABC", "Active");
    INSERT INTO `items` VALUES("3", "Routers", "7600 Series", "blah blah", "Cisco", "980.45", "DEF", "Active");
    INSERT INTO `items` VALUES("4", "Monitors", "Flat Screen", "17\" blah blah blah", "HP", "453.20", "DEF", "Active");
    INSERT INTO `items` VALUES("5", "Monitors", "Flat Screen", "17\" ldkfhfdn ds;kfj", "IBM", "321.45", "GHI", "Active");
    INSERT INTO `items` VALUES("6", "Monitors", "CRT", "kjh", "HP", "210.00", "DEF", "Inactive");
    INSERT INTO `items` VALUES("7", "N/A", "- Select Item -", "N/A", "N/A", "0.00", "N/A", "Active");
    INSERT INTO `items` VALUES("10", "Routers", "7600 Series", "", "Cisco", "525.35", "JKL", "Active");
    INSERT INTO `items` VALUES("9", "Routers", "7600 Series", "", "Cisco", "548.00", "GHI", "Active");
    
    
    #
    # Table structure for table 'ticket'
    #
    
    CREATE TABLE `ticket` (
      `t_id` int(7) unsigned NOT NULL auto_increment,
      `t_category` varchar(50) NOT NULL default '',
      `t_detail` blob,
      `t_priority` smallint(1) unsigned default NULL,
      `t_user` varchar(50) NOT NULL default '',
      `t_timestamp_opened` datetime default NULL,
      `t_timestamp_closed` datetime default NULL,
      `t_department` varchar(50) NOT NULL default '',
      `t_location` varchar(20) NOT NULL default '',
      `t_summary` varchar(60) NOT NULL default '',
      `t_userfirstname` varchar(30) default NULL,
      `t_userlastname` varchar(30) default NULL,
      `t_usertelephone` varchar(30) default NULL,
      `t_useremail` varchar(30) default NULL,
      `t_computerid` varchar(50) default NULL,
      `t_sitename` varchar(50) NOT NULL default '',
      `t_passettag` varchar(20) default NULL,
      `t_stvno` varchar(20) NOT NULL default '',
      `date_required` varchar(30) default NULL,
      `t_supplier_name` varchar(50) NOT NULL default '',
      `t_remark` text,
      `t_pono` varchar(45) default NULL,
      `t_reqno` varchar(15) NOT NULL default '',
      PRIMARY KEY  (`t_id`)
    ) ENGINE=MyISAM DEFAULT CHARSET=latin1;
    
    
    
    #
    # Dumping data for table 'ticket'
    #
    
    INSERT INTO `ticket` VALUES("21", "Purchase", "", "1", "admin", "2005-08-17 20:56:00", NULL, "IT", "", "monitor, router", "justin", "", "445577", "", NULL, "102 Villas Hattan", "", "", "", "1", NULL, "", "222");
    
    
    #
    # Table structure for table 'ticketitems'
    #
    
    CREATE TABLE `ticketitems` (
      `id` int(10) unsigned NOT NULL auto_increment,
      `t_id` int(10) unsigned NOT NULL default '0',
      `ItemOrder` int(10) unsigned NOT NULL default '0',
      `ItemName` varchar(255) NOT NULL default '',
      `ItemQty` int(10) unsigned NOT NULL default '0',
      PRIMARY KEY  (`id`)
    ) ENGINE=MyISAM DEFAULT CHARSET=latin1;
    
    
    
    #
    # Dumping data for table 'ticketitems'
    #
    
    INSERT INTO `ticketitems` VALUES("27", "21", "2", "7600 Series", "3");
    INSERT INTO `ticketitems` VALUES("26", "21", "1", "Flat Screen", "2");
    I sincerely thank you all for the help & shared knowledge. - cyp

  2. #2
    SitePoint Evangelist ldivinag's Avatar
    Join Date
    Jan 2005
    Location
    N37 33* W122 3*
    Posts
    414
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    javascript is what you need.

    since php is a SERVER side language, only when the user submits the form to the server will the changes be seen.

    javascript, on the other hand is a CLIENT side.

    so you make changes on the client, then it will be affected immediately...
    leo d.

  3. #3
    SitePoint Enthusiast
    Join Date
    May 2005
    Posts
    44
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by ldivinag
    javascript is what you need.

    since php is a SERVER side language, only when the user submits the form to the server will the changes be seen.

    javascript, on the other hand is a CLIENT side.

    so you make changes on the client, then it will be affected immediately...

    thanks for the reply leo, but thats not the solution i am looking for.. if you have read the scenario above then you'd probably get a clearer insight or maybe my explanation was kinda vague ...anyways i have tried the dynamic checkboxes for suppliers on a different module and the codes goes something like this:

    PHP Code:
    <?
        
    //////////////////////////////////////////////////////////////////////
        // query the database and input all info from supplier into the listbox
        /* get the checkbox labels */

        
    $query "SELECT supplier_id,supplier_name FROM supplier ORDER BY supplier_name ASC;";
        
    $mysql_result query($query);
        while (
    $row mysql_fetch_row($mysql_result)) {
            
    $pos strpos($t_supplier_name,$row[0]);
          if (
    $pos===false) {
          
    ?>
            <input type=checkbox name="lstSupplier[]" value="<? echo $row[0?>"><? echo $row[1?>
            <?
          
    }
          else {
            
    ?>
            <input type=checkbox name="lstSupplier[]" value="<? echo $row[0?>" checked><? echo $row[1?>
            <?


          
    }
        }
        
    ?>
    however when i tried experimenting that feature for the prices of the selected items, i am facing trouble or rather having a hard time doing it
    I sincerely thank you all for the help & shared knowledge. - cyp

  4. #4
    SitePoint Enthusiast
    Join Date
    May 2005
    Posts
    44
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    any suggestions guys?
    I sincerely thank you all for the help & shared knowledge. - cyp


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
  •