Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 9 of 9
  1. #1
    New Coder
    Join Date
    Jun 2012
    Location
    Delhi
    Posts
    23
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Question Select HTML Row and get cells Values.

    Hi,
    I working on a html table and want to get row wise information of that. please check the attachment.
    Select HTML Row and get cells Values.-click.jpg
    this is my code
    Code:
    <?php
    
     include ("db.php");
     $query_for_result=mysql_query("SELECT * FROM pro_production ORDER BY production_id");
    $num=mysql_numrows($query_for_result);
    mysql_close();
    ?>
    <div id="main" style="width: 100%; float:left; border:solid #CCCCCC; background-color:#FFFFFF; overflow:scroll; height:500px;">
    <table width="1800" align="center" border="1" cellspacing="0" cellpadding="0" style="font-family:Verdana, Arial, Helvetica, sans-serif; font-size:12px; color:#000000; border:solid #d6d4d5; border-width:1px; margin-top:0px;">
      <tr>
        <td>S.No.</td>
        <td>Booking Date</td>
        <td>Delivery Date</td>
        <td>Order Number</td>
        <td>Customer Name</td>
        <td>Status</td>
        <td>Product Range</td>
        <td>Cover</td>
        <td>Size</td>
        <td>Accessory</td>
        <td>Bag</td>
        <td>Packing</td>
        <td>Delivery</td>
        <td>Paper</td>
        <td>Coating</td>
        <td>Priority</td>
        <td>Advance</td>
        <td>G Total</td>
        <td>Balance</td>
      </tr>
      <?php
    $i=0;
    while ($i < $num)
     {
    $f1=mysql_result($query_for_result,$i,"production_id");
    $f2=mysql_result($query_for_result,$i,"booking_date");
    $f3=mysql_result($query_for_result,$i,"delivery_date");
    $f4=mysql_result($query_for_result,$i,"order_no");
    $f5=mysql_result($query_for_result,$i,"salutation");
    $f6=mysql_result($query_for_result,$i,"customer_name");
    $f7=mysql_result($query_for_result,$i,"status");
    $f8=mysql_result($query_for_result,$i,"product_range");
    $f9=mysql_result($query_for_result,$i,"cover");
    $f10=mysql_result($query_for_result,$i,"size");
    $f11=mysql_result($query_for_result,$i,"accessory");
    $f12=mysql_result($query_for_result,$i,"bag");
    $f13=mysql_result($query_for_result,$i,"packing");
    $f14=mysql_result($query_for_result,$i,"delivery");
    $f15=mysql_result($query_for_result,$i,"coating");
    $f16=mysql_result($query_for_result,$i,"priority");
    $f17=mysql_result($query_for_result,$i,"advance");
    $f18=mysql_result($query_for_result,$i,"gtotal");
    $f19=mysql_result($query_for_result,$i,"balance");
    $f20=$f5.$f6;
    $f21=mysql_result($query_for_result,$i,"paper");
    
    $id=$i+1;
    ?>
         <tr >		
       
        <td ><?php echo $id; ?></td>
        <td><?php echo $f2; ?></td>
        <td><?php echo $f3; ?></td>
        <td><?php echo $f4; ?></td>
        <td><?php echo $f20; ?></td>
        <td><?php echo $f7; ?></td>
        <td><?php echo $f8; ?></td>
        <td><?php echo $f9; ?></td>
        <td><?php echo $f10; ?></td>
        <td><?php echo $f11; ?></td>
        <td><?php echo $f12; ?></td>
        <td><?php echo $f13; ?></td>
        <td><?php echo $f14; ?></td>
        <td><?php echo $f21; ?></td>
        <td><?php echo $f15; ?></td>
        <td><?php echo $f16; ?></td>
        <td><?php echo $f17; ?></td>
        <td><?php echo $f18; ?></td>
        <td><?php echo $f19; ?></td>
    
      </tr>
      <?php
    $i++;
    
    }
    
    ?>
    
    </table>
    </div>
    What i want that if i select row first and the click on any of the bottom buttons then i could get the whole information of that row.
    I have done lot of search but i only able to get the data when click on the row itself but not when i clicked on the bottom button,

    So if any one can help me in this regard then i will be very thankful.

    thanks

  • #2
    Master Coder
    Join Date
    Jun 2003
    Location
    Cottage Grove, Minnesota
    Posts
    9,472
    Thanks
    8
    Thanked 1,085 Times in 1,076 Posts
    I wanted to do a "proof of concept" test, so I created my own table using your layout. Since I don't have your MySQL, I just made-up data.

    The point is, when you click a row, you need to highlight the row and also find out what the ID (S. No.) is for the row you clicked. That ID is saved two ways. In real-time, without refresh, the ID is written to a span class called "stat". Also, when you click a row, the ID of that row is sent to a PHP script for processing. That script also saves the ID in a SESSION to be used elsewhere.

    Once you click a row, because you know the ID, you can then click the buttons at the bottom to call other PHP scripts. Query the SESSION to see which row is highlighted.

    So the key to the whole thing is ... depending on what your bottom buttons do, if those buttons execute any other PHP scripts, you can query the SESSION in any of those scripts and know which row ("S. No.") has been selected in the table. Knowing that unique number is all you need to do any queries in any other scripts.

    You may decide to do this with AJAX (JQuery, PHP) and do everything without leaving the page. In that case, you also know the S. No. because that is contained in the class called "stat".

    This is my proof of concept working test: http://www.catpin.com/tr.php

    Here is my test script:
    Code:
    <?php
    session_start();
    
    $appid="";
    if(isset($_SESSION['appid'])){
    $appid=$_SESSION['appid'];
    }
    ?>
    
    <!DOCTYPE html>
    <html>
    	<head>
    		<meta charset="utf-8">
    		<title>TR Row Test</title>
    		<script src="//ajax.googleapis.com/ajax/libs/jquery/1.11.0/jquery.min.js"></script>
    	</head>
         <style type="text/css">
         .rowCSS{background-color:#f0f0f0;}
         </style>
        <script type="text/javascript">
            $(function () {
                var trInstance = $('#dataGrid').find('tr');
                trInstance.click(function () {
                    trInstance.removeClass('rowCSS');
                     var instance = $(this);
                    instance.addClass('rowCSS');
    				$.get("appid.php?id=" + $(this).find(".appid").html(), function(data){
    				$('.stat').html(data);
    				});
                });
            });
        </script>
    <body>	
    <br /><br />
    Current ID in SESSION (refresh browser to see this value): <?=$appid?><br /><br />
    Current ID Selected via JQuery (this value is updated without refresh):  <span class="stat"> &nbsp; </span>
    <br /><br />
    <div id="main" style="width: 100%; float:left; border:solid #CCCCCC; background-color:#FFFFFF; overflow:scroll; height:500px;">
    <table id="dataGrid" width="1800" align="center" border="1" cellspacing="0" cellpadding="0" style="font-family:Verdana, Arial, Helvetica, sans-serif; font-size:12px; color:#000000; border:solid #d6d4d5; border-width:1px; margin-top:0px;">
      <tr>
        <td>S.No.</td>
        <td>Booking Date</td>
        <td>Delivery Date</td>
        <td>Order Number</td>
        <td>Customer Name</td>
        <td>Status</td>
        <td>Product Range</td>
        <td>Cover</td>
        <td>Size</td>
        <td>Accessory</td>
        <td>Bag</td>
        <td>Packing</td>
        <td>Delivery</td>
        <td>Paper</td>
        <td>Coating</td>
        <td>Priority</td>
        <td>Advance</td>
        <td>G Total</td>
        <td>Balance</td>
      </tr>
      <?php
    
    $id="123";
    $f2="cell 2";
    $f3="cell 3";
    $f4="cell 4";
    $f5="cell 5";
    $f6="cell 6";
    $f7="cell 7";
    $f8="cell 8";
    $f9="cell 9";
    $f10="cell 10";
    $f11="cell 11";
    $f12="cell 12";
    $f13="cell 13";
    $f14="cell 14";
    $f15="cell 15";
    $f16="cell 16";
    $f17="cell 17";
    $f18="cell 18";
    $f19="cell 19";
    $f20="cell 20";
    ?>
         <tr>		
        <td class="appid"><?php echo $id; ?></td>
        <td><?php echo $f2; ?></td>
        <td><?php echo $f3; ?></td>
        <td><?php echo $f4; ?></td>
        <td><?php echo $f20; ?></td>
        <td><?php echo $f7; ?></td>
        <td><?php echo $f8; ?></td>
        <td><?php echo $f9; ?></td>
        <td><?php echo $f10; ?></td>
        <td><?php echo $f11; ?></td>
        <td><?php echo $f12; ?></td>
        <td><?php echo $f13; ?></td>
        <td><?php echo $f14; ?></td>
        <td><?php echo $f21; ?></td>
        <td><?php echo $f15; ?></td>
        <td><?php echo $f16; ?></td>
        <td><?php echo $f17; ?></td>
        <td><?php echo $f18; ?></td>
        <td><?php echo $f19; ?></td>
      </tr>
      
           <tr>		
        <td class="appid">546</td>
        <td><?php echo $f2; ?></td>
        <td><?php echo $f3; ?></td>
        <td><?php echo $f4; ?></td>
        <td><?php echo $f20; ?></td>
        <td><?php echo $f7; ?></td>
        <td><?php echo $f8; ?></td>
        <td><?php echo $f9; ?></td>
        <td><?php echo $f10; ?></td>
        <td><?php echo $f11; ?></td>
        <td><?php echo $f12; ?></td>
        <td><?php echo $f13; ?></td>
        <td><?php echo $f14; ?></td>
        <td><?php echo $f21; ?></td>
        <td><?php echo $f15; ?></td>
        <td><?php echo $f16; ?></td>
        <td><?php echo $f17; ?></td>
        <td><?php echo $f18; ?></td>
        <td><?php echo $f19; ?></td>
      </tr>
      
           <tr>		
        <td class="appid">2325</td>
        <td><?php echo $f2; ?></td>
        <td><?php echo $f3; ?></td>
        <td><?php echo $f4; ?></td>
        <td><?php echo $f20; ?></td>
        <td><?php echo $f7; ?></td>
        <td><?php echo $f8; ?></td>
        <td><?php echo $f9; ?></td>
        <td><?php echo $f10; ?></td>
        <td><?php echo $f11; ?></td>
        <td><?php echo $f12; ?></td>
        <td><?php echo $f13; ?></td>
        <td><?php echo $f14; ?></td>
        <td><?php echo $f21; ?></td>
        <td><?php echo $f15; ?></td>
        <td><?php echo $f16; ?></td>
        <td><?php echo $f17; ?></td>
        <td><?php echo $f18; ?></td>
        <td><?php echo $f19; ?></td>
      </tr>
    
    </table>
    </div>
    </body>
    </html>

    Here is the script called "appid.php", which is executed whenever a row is clicked:
    Code:
    <?php
    session_start();
    
    if($_GET['id']){
    $_SESSION['appid']=$_GET['id'];
    echo $_GET['id'];
    }
    else{
    echo "none";
    }
    ?>
    Last edited by mlseim; 04-16-2014 at 07:42 PM.

  • #3
    New Coder
    Join Date
    Jun 2012
    Location
    Delhi
    Posts
    23
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Hi,
    This is what i want to achieve

    step-1
    Select HTML Row and get cells Values.-step-1.jpg

    step-2
    Select HTML Row and get cells Values.-step-2.jpg
    Thanks

  • #4
    Master Coder
    Join Date
    Jun 2003
    Location
    Cottage Grove, Minnesota
    Posts
    9,472
    Thanks
    8
    Thanked 1,085 Times in 1,076 Posts
    That's exactly what I posted in my example (functionally anyhow). I of course don't have your database, your CSS, or your HTML. My example is for you to see how the javascript and SESSION works.

    The problem is, I have no idea what the buttons at the bottom do. Is each one of those buttons a PHP script that perform the desired operation? Do you have PHP scripts for those operations?

    Again, look at my example: TR Row Test

    You click any row and it highlights (gray). At that point, the script knows which "S. No." (or unique ID) you have selected. That's all you need to know before clicking a button at the bottom. When you click a button at the bottom, that script will process all of the information in the row by querying for "S. No."

    When you do click a button at the bottom, another PHP is executed. Just look at the existing $_SESSION['appid'] to do another query. That will allow you to get all of the column values for that row. And also know, I just picked "S. No." as the unique ID for each row. You may decide to use "Order Number" as the unique ID ... it doesn't matter. As long as each row has some unique number that no other row has, that becomes the ID you use for queries.

    And finally, I assume the person that uses your scripts has to log-in? Again, that will utilize PHP SESSION. That is something you probably want to learn how to use.
    Last edited by mlseim; 04-17-2014 at 01:58 PM.

  • #5
    New Coder
    Join Date
    Apr 2014
    Posts
    17
    Thanks
    0
    Thanked 1 Time in 1 Post
    You are going to definitely need to incorporate some JavaScript with your page to perform the row highlighting and row selection.

    As mlseim has said you need a way for the row ID to be 'saved' somewhere on your page so that when you click one of your buttons the 'saved' row ID can be sent along with the form data to a processing PHP script. As mlseim has said you could have the ID saved to a hidden span tag. You are going to need a fairly simple JavaScript function that works in the following way.

    1) function is activated when a row is clicked. The function should be passed the row ID value (contents of row S. No).
    2) row background of selected row, changed to the appropriate highlight colour using the ID value as reference.
    3) row ID saved to a hidden span.

    As your form has multiple buttons and because html forms don't give the option for different buttons to send to different PHP scripts, you are going to need to write more JavaScript to handle your various button events. Maybe someone in the JavaScript forum would be better suited to direct you with this.

  • #6
    Master Coder
    Join Date
    Jun 2003
    Location
    Cottage Grove, Minnesota
    Posts
    9,472
    Thanks
    8
    Thanked 1,085 Times in 1,076 Posts
    Everything in my example is complete, the way he wishes it to work. It's the other scripts (the buttons on the bottom) that don't have scripts for them (as far as I know).

    Since he is using PHP/MySQL, a SESSION is the perfect solution. No hidden form values or anything needed to keep track of the 'active' row.

  • #7
    New Coder
    Join Date
    Apr 2014
    Posts
    17
    Thanks
    0
    Thanked 1 Time in 1 Post
    My bad mlseim, sorry I read your posts but didn't read your working example code. Didn't realise you had the JavaScript working for the highlighting and ID selection. Will make sure to read more carefully in the future

  • #8
    New Coder
    Join Date
    Jun 2012
    Location
    Delhi
    Posts
    23
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Hi mlseim,
    thanks for you code its very nicely done by you,
    Please check this link,
    Edit fiddle - JSFiddle

    This is what i want to do but using PHP.
    Can it be done?
    and want every values in a variable one bye one.
    Moreover can you post the whole code, as i use your above code but its not working.
    Please suggest.
    thanks
    Last edited by rajeshkr; 04-19-2014 at 06:56 AM.

  • #9
    Master Coder
    Join Date
    Jun 2003
    Location
    Cottage Grove, Minnesota
    Posts
    9,472
    Thanks
    8
    Thanked 1,085 Times in 1,076 Posts
    In your first post, you showed us the PHP script you used to display your table. You did a query and looped through the results.

    In my example, I highlight the row from your <table> and save the "production_id" in a PHP SESSION. This has nothing to do with any other scripts, like "Create Estimate". You can run any other script you want, and you'll always know which 'production_id' the user is looking at, because that ID is saved in a SESSION variable.

    So now, you create a button that says "Create Estimate". When you click that button, you'll execute another PHP script that creates the estimate.

    I have no access to your database, so I cannot provide a script. What I provided works just fine (to save the 'production_id' in a SESSION). Only you can create the other scripts. We cannot access your database.

    Here's what it might look like (untested) ... using the PHP SESSION that my script created when the table row is selected:

    Save this as "estimate.php" and see what it does...

    Code:
    <?php
    session_start();
    
    $appid="none";
    if(isset($_SESSION['appid'])){
    $appid=$_SESSION['appid']);
    }
    
    include ("db.php");
    $result=mysql_query("SELECT * FROM pro_production WHERE production_id='$appid' ") or die(mysql_error());
    $row = mysql_fetch_array( $result );
    $num_rows = mysql_num_rows($result);
    mysql_close();
    
    // You're only expecting one row ... display it ...
    if($num_rows==1){
    
    echo "ID: ".$row['production_id']."<br />";
    echo "Booking Date: ".$row['booking_date']."<br />";
    echo "Delivery Date: ".$row['delivery_date']."<br />";
    
    // etc.
    }
    
    ?>
    Last edited by mlseim; 04-19-2014 at 02:38 PM.


  •  

    Tags for this Thread

    Posting Permissions

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