Thread: Help with creating a dynamic table

Results 1 to 3 of 3
  1. #1 Help with creating a dynamic table 
    Registered Member

    Join Date
    Nov 2012
    Posts
    72
    Thanks given
    23
    Thanks received
    11
    Rep Power
    116
    Essentially I'm building a table from mysql that has a td where users can input data manually (there is also a set default price). In another td it does a formula based on the number the user inputed multiplied by the price of the item and gives a total. Then in another td there is a button. On button press it will add a new row to a table above if that item doesn't already exist in the table. If it does exist it will add on to the existing data in the table.


    So far I have the drop table being created already using this code:

    Code:
      <button class="btn btn-info" data-toggle="collapse" data-target="#common">Common</button>
      <div id="common" class="collapse in">
        <table class="table table-bordered">
          <thead>
            <tr>
              <th>Item</th>
              <th>Quantity</th>
              <th>Rarity</th>
              <th>Price</th>
              <th>Add Drop</th>
            </tr>
          </thead>
          <tbody>
            <?php 
    
            $sql = mysql_query("SELECT * 
            FROM `monster_items` INNER JOIN `items`
            ON monster_items.item_id = items.item_id
            WHERE monster_id = '$npcid' AND rarity = 'Common'");
    
            if($sql) 
            {
              while ($result = mysql_fetch_assoc($sql))
              {
                  echo '<tr><td>'.$result['item_name'].'</td>';
                  echo '<td class="col-xs-2"><input onchange="getPrice" id="a'.$result['id'].'" type="number" value="'.$result['quantity'].'" class="form-control col-xs-2 input-sm"></td>';
                  echo '<td>'.$result['rarity'].'</td>';
                  $final_price = $result['sell_average']*$result['quantity'];
                  echo '<td>'.number_format($final_price).'</td>';
                  echo '<td><button id="'.$result['item_id'].'" class="btn-xs btn-success">Add Drop</button></td>';
              }
            }
            ?>
          </tbody>
        </table>
      </div>
    This code creates this:


    The part I need help with is the user input doesn't not actually update the data (I assume I need some sort of jquery/javascript code to update that?)


    After I get the first part done, I'll want to make the button functional.

    Here is the code for the table that data will be appended to:
    Code:
    <table class="table table-bordered">
      <div class="col-sm-12 text-center">
        <h4>
          Total Drops Received
        </h4>
      </div>
      <thead>
        <tr>
          <td colspan="1">Total Price:</td>
          <td colspan="2">999,999,999 GP</td>
        </tr>
        <tr>
          <th>Item</th>
          <th>Quantity Received</th>
          <th>Price</th>
        </tr>
      </thead>
      <tbody>
        <tr>
          <td>Pure Essence</td>
          <td>600</td>
          <td>4800</td>
        </tr>
      </tbody>
    </table>
    However if an item already exists in that table, let's say 600 pure essence is in the table, and you hit the button to add pure ess, it will then be 1,200 and the correct price.


    If anyone is willing to help me with this it will be much appreciated! At least a push in the right direction would be awesome! I'm still a beginner programmer and have been self teaching myself.
    Reply With Quote  
     

  2. #2  
    Registered Member

    Join Date
    Nov 2012
    Posts
    72
    Thanks given
    23
    Thanks received
    11
    Rep Power
    116
    Still looking for help on this if anyone is available to send me in the right direction.
    Reply With Quote  
     

  3. #3  
    ???

    funkE's Avatar
    Join Date
    Feb 2008
    Posts
    2,612
    Thanks given
    255
    Thanks received
    989
    Rep Power
    1366
    Either make everything editable a form element or use ajax. Php will send the updates to the db
    .
    Reply With Quote  
     


Thread Information
Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)


User Tag List

Similar Threads

  1. need help with creating a pking shop
    By Dark9Boy in forum Help
    Replies: 14
    Last Post: 02-04-2014, 07:09 PM
  2. Replies: 30
    Last Post: 01-04-2014, 11:53 PM
  3. Need help with creating shops.
    By Mitver in forum Help
    Replies: 0
    Last Post: 06-27-2011, 10:15 PM
  4. Need help with creating a C# runescape server...
    By Harha in forum Application Development
    Replies: 5
    Last Post: 08-18-2010, 04:49 PM
  5. Help with creating area
    By zakc20 in forum Help
    Replies: 4
    Last Post: 04-06-2010, 07:15 PM
Posting Permissions
  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •