I need a little bit help

Discussion in 'PHP' started by baris22, Oct 19, 2009.

  1. #1
    Hello,

    I have been trying for 2 hours now but i could not do.

    This is the image of current output:
    [​IMG]

    I want to make it like this:

    [​IMG]

    If item amount is more than 1 i want to have that many select box for the worker. How can i do this?

    Thanks alot.

    
    
    <? 
    		$query1 = "SELECT * FROM item WHERE order_reference_number='$ref' GROUP BY item_amount";
    	    $portfolio = mysql_query($query1);
    		while($row1 = mysql_fetch_array($portfolio)) { 
    		?>
                <br />
              <table width="100%">
                <tr>
                  <td>
    <input name="item_amount" type="text" value="<?=$row1['item_amount'];?>" size="2" /> of <input name="item_name" type="text" value="<?=$row1['item_name'];?>" size="30" /> 
    Chooce a worker for this job 
    
    <select name="">
    <option>select</option>
    <option><?=$row1['item_amount'];?></option>
    </select>
    
    <select name="worker" id="worker">
           <option value="Select">Select</option>
       <?	
        $query3 = "SELECT * FROM worker";
    	$portfolio1 = mysql_query($query3);
        while($row3 = mysql_fetch_array($portfolio1)) { 
       ?>     
          <option><?=$row3['worker_name'];?></option>
    <? } ?>
    </select>
    </td>
      </tr>
      </table>
      <? } ?>    
    
    
    PHP:
     
    baris22, Oct 19, 2009 IP
  2. orionoreo

    orionoreo Peon

    Messages:
    145
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #2
    first of all its Choice not chooce


    anyways I can't run this because I don't have the tables but look at this part

    
      <input name="item_amount" type="text" value="<?php=$row1['item_amount'];?>" size="2" /> of <input name="item_name" type="text" value="<?php=$row1['item_name'];?>" size="30" />
    
          Chooce a worker for this job
    
          <select name="">
    
          <option>select</option>
    
          <option><?php=$row1['item_amount'];?></option>
    
          </select>
    
           
    
          <select name="worker" id="worker">
    
                 <option value="Select">Select</option>
    
             <?php  
    
              $query3 = "SELECT * FROM worker";
    
              $portfolio1 = mysql_query($query3);
    
              while($row3 = mysql_fetch_array($portfolio1)) {
    
             ?>    
    
                <option><?php=$row3['worker_name'];?></option>
    
          <?php } ?>
    
          </select>
    
    PHP:

    this needs a loop as such

    
     <input name="item_amount" type="text" value="<?php=$row1['item_amount'];?>" size="2" /> of <input name="item_name" type="text" value="<?php=$row1['item_name'];?>" size="30" />
    
          Chooce a worker for this job
          
          <?php
    	  
    	  for ($i = 0; $i<$row['item_amount']; $i++) {
    		  
    		?>
    
          <select name="<?php echo 'select_A_'.$i; ?>">
    
          <option>select</option>
    
          <option><?php=$row1['item_amount'];?></option>
    
          </select>
    
           
    
          <select name="worker_A_<?php echo $i; ?>" id="worker_A_<?php echo $i; ?>">
    
                 <option value="Select">Select</option>
    
             <?php  
    
              $query3 = "SELECT * FROM worker";
    
              $portfolio1 = mysql_query($query3);
    
              while($row3 = mysql_fetch_array($portfolio1)) {
    
             ?>    
    
                <option><?php=$row3['worker_name'];?></option>
    
          <?php } ?>
    
          </select>
          
          <?php 
    	  
    	  }
    	  
    	  ?>
    
    PHP:
     
    orionoreo, Oct 19, 2009 IP
  3. baris22

    baris22 Active Member

    Messages:
    543
    Likes Received:
    4
    Best Answers:
    0
    Trophy Points:
    60
    #3
    orionoreo thank you for your replie. It did not work either. This is the database i use.

    Thanks again


    -- phpMyAdmin SQL Dump
    -- version 2.10.3
    -- http://www.phpmyadmin.net
    --
    -- Host: localhost
    -- Generation Time: Oct 19, 2009 at 06:51 PM
    -- Server version: 5.0.51
    -- PHP Version: 5.2.6

    SET SQL_MODE="NO_AUTO_VALUE_ON_ZERO";

    --
    -- Database: `terzi`
    --

    -- --------------------------------------------------------

    --
    -- Table structure for table `item`
    --

    CREATE TABLE `item` (
    `item_id` int(11) NOT NULL auto_increment,
    `item_name` varchar(255) default NULL,
    `item_amount` int(11) default NULL,
    `item_fee` double(16,2) NOT NULL default '0.00',
    `item_detail` text,
    `item_work_start_time` datetime default NULL,
    `item_work_finish_time` datetime default NULL,
    `item_done` char(2) NOT NULL default 'N',
    `order_reference_number` varchar(4) default NULL,
    `worker_id` int(11) default NULL,
    PRIMARY KEY (`item_id`)
    ) ENGINE=MyISAM DEFAULT CHARSET=utf8 AUTO_INCREMENT=18 ;

    --
    -- Dumping data for table `item`
    --

    INSERT INTO `item` VALUES (1, 'shirt', 1, 0.00, '', '0000-00-00 00:00:00', '0000-00-00 00:00:00', '', 'A001', 0);
    INSERT INTO `item` VALUES (2, 'shirt', 1, 0.00, '', '0000-00-00 00:00:00', '0000-00-00 00:00:00', '', 'A002', 0);
    INSERT INTO `item` VALUES (3, 'shirt', 1, 0.00, '', '0000-00-00 00:00:00', '0000-00-00 00:00:00', '', 'A003', 0);
    INSERT INTO `item` VALUES (4, 'shirt', 2, 0.00, '', '0000-00-00 00:00:00', '0000-00-00 00:00:00', '', 'A004', 0);
    INSERT INTO `item` VALUES (5, 'shirt', 2, 0.00, '', '0000-00-00 00:00:00', '0000-00-00 00:00:00', '', 'A004', 0);
    INSERT INTO `item` VALUES (6, 'trousers', 3, 0.00, '', '0000-00-00 00:00:00', '0000-00-00 00:00:00', '', 'A005', 0);
    INSERT INTO `item` VALUES (7, 'trousers', 3, 0.00, '', '0000-00-00 00:00:00', '0000-00-00 00:00:00', '', 'A005', 0);
    INSERT INTO `item` VALUES (8, 'trousers', 3, 0.00, '', '0000-00-00 00:00:00', '0000-00-00 00:00:00', '', 'A005', 0);
    INSERT INTO `item` VALUES (9, 'jacket', 4, 0.00, '', '0000-00-00 00:00:00', '0000-00-00 00:00:00', '', 'A005', 0);
    INSERT INTO `item` VALUES (10, 'jacket', 4, 0.00, '', '0000-00-00 00:00:00', '0000-00-00 00:00:00', '', 'A005', 0);
    INSERT INTO `item` VALUES (11, 'jacket', 4, 0.00, '', '0000-00-00 00:00:00', '0000-00-00 00:00:00', '', 'A005', 0);
    INSERT INTO `item` VALUES (12, 'jacket', 4, 0.00, '', '0000-00-00 00:00:00', '0000-00-00 00:00:00', '', 'A005', 0);
    INSERT INTO `item` VALUES (13, 'shirt', 1, 0.00, '', '0000-00-00 00:00:00', '0000-00-00 00:00:00', '', 'A005', 0);
    INSERT INTO `item` VALUES (14, 'shirt', 3, 0.00, '', '0000-00-00 00:00:00', '0000-00-00 00:00:00', '', 'A006', 0);
    INSERT INTO `item` VALUES (15, 'shirt', 3, 0.00, '', '0000-00-00 00:00:00', '0000-00-00 00:00:00', '', 'A006', 0);
    INSERT INTO `item` VALUES (16, 'shirt', 3, 0.00, '', '0000-00-00 00:00:00', '0000-00-00 00:00:00', '', 'A006', 0);
    INSERT INTO `item` VALUES (17, 'jacket', 1, 0.00, '', '0000-00-00 00:00:00', '0000-00-00 00:00:00', '', 'A006', 0);

    -- --------------------------------------------------------

    --
    -- Table structure for table `material`
    --

    CREATE TABLE `material` (
    `material_id` int(11) NOT NULL auto_increment,
    `material_name` varchar(255) default NULL,
    `material_sort` int(11) default NULL,
    PRIMARY KEY (`material_id`)
    ) ENGINE=MyISAM DEFAULT CHARSET=utf8 AUTO_INCREMENT=31 ;

    --
    -- Dumping data for table `material`
    --

    INSERT INTO `material` VALUES (28, 'shirt', NULL);
    INSERT INTO `material` VALUES (29, 'trousers', NULL);
    INSERT INTO `material` VALUES (30, 'jacket', NULL);

    -- --------------------------------------------------------

    --
    -- Table structure for table `orderr`
    --

    CREATE TABLE `orderr` (
    `order_id` int(11) NOT NULL auto_increment,
    `order_reference_number` varchar(4) default NULL,
    `order_description` text NOT NULL,
    `order_time` datetime default NULL,
    `order_collect_time` text,
    `order_collected` varchar(15) default NULL,
    `order_fee` double(16,2) NOT NULL default '0.00',
    `order_deposit` double(16,2) NOT NULL default '0.00',
    `order_rest_fee` double(16,2) NOT NULL default '0.00',
    `order_paid_all` char(2) NOT NULL default 'N',
    `order_comment` text,
    `order_customer_name` varchar(255) default NULL,
    `order_customer_address` varchar(255) default NULL,
    `order_customer_phone` varchar(30) default NULL,
    `order_customer_comment` text,
    `order_total_items` int(4) NOT NULL,
    PRIMARY KEY (`order_id`),
    UNIQUE KEY `order_reference_number` (`order_reference_number`)
    ) ENGINE=MyISAM DEFAULT CHARSET=utf8 AUTO_INCREMENT=7 ;

    --
    -- Dumping data for table `orderr`
    --

    INSERT INTO `orderr` VALUES (1, 'A001', '', '0000-00-00 00:00:00', '', '1', 0.00, 0.00, 0.00, 'no', 'order_comment', '1', '', '', 'customer_comment', 1);
    INSERT INTO `orderr` VALUES (2, 'A002', '', '0000-00-00 00:00:00', '', '1', 0.00, 0.00, 0.00, 'no', 'order_comment', '', '', '', 'customer_comment', 1);
    INSERT INTO `orderr` VALUES (3, 'A003', '', '0000-00-00 00:00:00', '', '1', 0.00, 0.00, 0.00, 'no', 'order_comment', '', '', '', 'customer_comment', 1);
    INSERT INTO `orderr` VALUES (4, 'A004', '', '0000-00-00 00:00:00', '', '1', 0.00, 0.00, 0.00, 'no', 'order_comment', '', '', '', 'customer_comment', 2);
    INSERT INTO `orderr` VALUES (5, 'A005', '', '0000-00-00 00:00:00', '', '1', 0.00, 0.00, 0.00, 'no', 'order_comment', 'f', '', '', 'customer_comment', 8);
    INSERT INTO `orderr` VALUES (6, 'A006', '', '0000-00-00 00:00:00', '', '1', 0.00, 0.00, 0.00, 'no', 'order_comment', 'yy', '', '', 'customer_comment', 4);

    -- --------------------------------------------------------

    --
    -- Table structure for table `worker`
    --

    CREATE TABLE `worker` (
    `worker_id` int(11) NOT NULL auto_increment,
    `worker_name` varchar(255) default NULL,
    `worker_sort` int(11) default NULL,
    PRIMARY KEY (`worker_id`)
    ) ENGINE=MyISAM DEFAULT CHARSET=utf8 AUTO_INCREMENT=73 ;

    --
    -- Dumping data for table `worker`
    --

    INSERT INTO `worker` VALUES (70, 'mustafa yilmaz', NULL);
    INSERT INTO `worker` VALUES (71, 'mehmet emin', NULL);
    INSERT INTO `worker` VALUES (72, 'ahmet', NULL);
     
    baris22, Oct 19, 2009 IP
  4. orionoreo

    orionoreo Peon

    Messages:
    145
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #4
    ok sorry I named the array wrong it works now

    
    <?php
    
    $query1 = "SELECT * FROM item WHERE order_reference_number='$ref' GROUP BY item_amount";
    $portfolio = mysql_query($query1);
    
    while($row1 = mysql_fetch_array($portfolio)) {
    
    ?>
    
                  <br />
    
                <table width="100%">
    
                  <tr>
    
                    <td valign="top" width="300">
    
      <input name="item_amount" type="text" value="<?php echo $row1['item_amount']; ?>" size="2" /> of <input name="item_name" type="text" value="<?php echo $row1['item_name'];?>" size="30" />
    	
        </td>
        <td>
    
       <?php
       
       for ($i=0; $i<$row1['item_amount']; $i++) {
    	   
    	?>
        
         Choice a worker for this job
    
      <select name="">
    
      <option>select</option>
    
      <option><?php echo $row1['item_amount']; ?></option>
    
      </select>
    
       
    
      <select name="worker" id="worker">
    
             <option value="Select">Select</option>
    
         <?php  
    
          $query3 = "SELECT * FROM worker";
    
          $portfolio1 = mysql_query($query3);
    
          while($row3 = mysql_fetch_array($portfolio1)) {
    
         ?>    
    
            <option><?php echo $row3['worker_name'];?></option>
    
      <?php } ?>
    
      </select><br />
    
    	<?php
    	
       }
       
       ?>
      </td>
    
        </tr>
    
        </table>
    
        <?php } ?>
    
    PHP:
     
    orionoreo, Oct 19, 2009 IP
  5. baris22

    baris22 Active Member

    Messages:
    543
    Likes Received:
    4
    Best Answers:
    0
    Trophy Points:
    60
    #5
    It is working perfect . Thank you very much. 1 more thing...

    
    
    <select name="">
    
      <option>select</option>
    
      <option><?php echo $row1['item_amount']; ?></option>
    
      </select>
    
    
    PHP:
    if the item amount is 3 what can i do to have values 1 and 2?

    
    
    <select name="">
    
      <option>select</option>
      <option>1</option>
      <option>2</option>
      <option><?php echo $row1['item_amount']; ?></option>
    
      </select>
    
    
    PHP:
     
    baris22, Oct 19, 2009 IP
  6. orionoreo

    orionoreo Peon

    Messages:
    145
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #6
    sorry i'm not quite understanding your question
     
    orionoreo, Oct 19, 2009 IP
  7. baris22

    baris22 Active Member

    Messages:
    543
    Likes Received:
    4
    Best Answers:
    0
    Trophy Points:
    60
    #7
    Ok.

    this is the select box for item amount

    
    
    <select name="">
    <option>select</option>
    <option><?php echo $row1['item_amount']; ?></option>
    </select>
    
    
    PHP:
    At the moment

    If the value for <?php echo $row1['item_amount']; ?> is "1", items select box has got the value "select" and "1"

    and

    If the value for <?php echo $row1['item_amount']; ?> is "2", items select box has got the value "select" and "2"

    and

    If the value for <?php echo $row1['item_amount']; ?> is "3", items select box has got the value "select" and "3"

    so on...

    I want to do:

    If the value for <?php echo $row1['item_amount']; ?> is "1", items select box value should be "select" and "1"

    and

    If the value for <?php echo $row1['item_amount']; ?> is "2", items select box value should be "select", "1" and "2"

    and

    If the value for <?php echo $row1['item_amount']; ?> is "3", items select box value should be "select", "1", "2" and "3"

    so on...
     
    baris22, Oct 19, 2009 IP
  8. orionoreo

    orionoreo Peon

    Messages:
    145
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #8
    oic you want to change your select to this:

    
      <select name="">
    
      <option>select</option>
      
      <?php
      
      for ($s = 1; $s<=$row1['item_amount']; $s++) {
    		echo '<option>'.$s.'</option';  
      }
    
    ?>
    
      </select>
    PHP:
     
    orionoreo, Oct 19, 2009 IP
  9. baris22

    baris22 Active Member

    Messages:
    543
    Likes Received:
    4
    Best Answers:
    0
    Trophy Points:
    60
    #9
    waww. thanks for your help.
     
    baris22, Oct 19, 2009 IP
  10. ezprint2008

    ezprint2008 Well-Known Member

    Messages:
    611
    Likes Received:
    15
    Best Answers:
    2
    Trophy Points:
    140
    Digital Goods:
    1
    #10
    in english its "CHOOSE"
     
    ezprint2008, Oct 19, 2009 IP