www.webdeveloper.com
Results 1 to 6 of 6

Thread: Problem in displaying data in a table format

  1. #1
    Join Date
    Oct 2011
    Posts
    350

    Problem in displaying data in a table format

    Hi,

    Good day!

    I have a problem in displaying of data from database in a table format.

    I attached my codes,

    fab_spv_reports.php where you can select OP Number to display the table that I got a problem on displaying.

    By choosing OP Number kindly type SR131127001 then press the arrow down key in the keyboard, then press Enter key.

    get_fab_spv_process_reject_list_search.php is the php code for displaying of table.

    Also I attached my database, sample screenshots and the design that I desired to display.

    I hope somebody can help me to display the data in a table format which I desired to display.

    Any help is highly appreciated and also feel free to ask me if you have question.

    Thank you so much.
    Attached Files Attached Files

  2. #2
    Join Date
    Jul 2013
    Location
    Voorheesville NY USA
    Posts
    550
    From reading your post it's apparent that your problem is NOT "displaying data in table format". If it was just that, you wouldn't have included some much of your project. You want us to write it for you?

    When you have an isolated problem, then ask for help.

    PS - quite a few people here (incl. me) do NOT open attachments or go to websites to see your work.

  3. #3
    Join Date
    Oct 2011
    Posts
    350
    here is my fab_spv_reports.php
    PHP Code:
    <?php
     session_start
    ();
      
    ob_start();

        include(
    'connection.php');
      
      
    $update = isset($_POST['update']);
      
    $location 'fab_spv_reports.php';
       function 
    page_redirect($location)
     {
       echo 
    '<META HTTP-EQUIV="Refresh" Content="0; URL='.$location.'">';
       exit; 
     }
      

    if(
    $update)
    {
        
    $op_date        $_POST['op_date'];
        
    $op_number      $_POST['op_number'];
        
    $process_date   $_POST['process_date'];
        
    $section_id     $_POST['section_id'];
        
    $section_name   $_POST['section_name'];  
        
    $process_shift  $_POST['process_shift'];
        
    $supervisor     $_POST['supervisor'];

              
    $compound_type     $_POST['compound_type'];
            
    $op_output         $_POST['output'];    
              
            for(
    $s 0$s count($compound_type) ; $s++) 
            {
                
                    
    $sql_op "UPDATE op_output SET compound_output = '$op_output[$s]' WHERE compound_type = '$compound_type[$s]' AND op_number = '$op_number'";            
                   
    $result mysql_query($sql_op$con);
            }   

       
    page_redirect($location);
        
    }
      
      
    $op_date date('Y-m-d H:i:s');
    ?>
    <head>
    <script type="text/javascript" src="jquery.js"></script>
    <script type='text/javascript' src='jquery.autocomplete.js'></script>
    <link rel="stylesheet" type="text/css" href="jquery.autocomplete.css" />

    <script type="text/javascript">
    //-auto complete op_number

    $().ready(function() {
        $("#op_num").autocomplete("get_fab_spv_reports.php", {
           width: 175,
            matchContains: true,
            mustMatch: true,
            selectFirst: false
        });
        
        $("#op_num").result(function(event, data, formatted) {
        $("#op_number").val(data[0]);
        });
        
        $("#op_num").result(function(event, data, formatted) {
        $("#op_date").val(data[1]);
        });
      
        $("#op_num").result(function(event, data, formatted) {
        $("#section_name").val(data[2]);
        });
        
        $("#op_num").result(function(event, data, formatted) {
        $("#supervisor").val(data[3]);
        });
        
       $("#op_num").result(function(event, data, formatted) {
        $("#process_date").val(data[4]);
        });    
        
        $("#op_num").result(function(event, data, formatted) {
        $("#process_shift").val(data[5]);
        });
    }); 
    function AJAX(){
            var xmlHttp;
            try{
                xmlHttp=new XMLHttpRequest(); 
                return xmlHttp;
                }
            catch (e){
                try{
                    xmlHttp=new ActiveXObject("Msxml2.XMLHTTP"); 
                    return xmlHttp;
                    }
                catch (e){
                    try{
                        xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
                        return xmlHttp;
                        }
                    catch (e){
                        alert("Your browser does not support AJAX!");
                        return false;
                        }
                    }
                }
            }

    function getout()
            {
                if (window.event.keyCode==13 || window.event.keyCode==10) {
                divid = "op_output_fieldset";
                var url = "get_fab_spv_process_reject_list_search.php";
                var str = "id=" + document.getElementById("op_num").value;
                
                var xmlHttp = AJAX();
                xmlHttp.onreadystatechange =  function(){
                if(xmlHttp.readyState > 0 && xmlHttp.readyState < 4){
                    }
                if (xmlHttp.readyState == 4) {
                    if (xmlHttp.status == 200) {
                        var jsonart = xmlHttp.responseText;
                        document.getElementById(divid).innerHTML = jsonart;
                        }
                    }
                }
                xmlHttp.open("POST", url, true);
                xmlHttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
                xmlHttp.setRequestHeader("Content-length", str.length);
                xmlHttp.setRequestHeader("Connection", "close");
                xmlHttp.send(str);
              
            }
            }      
    </script>
    </head>
    <body>
    <form name="operator_report" action="<?php echo $PHP_SELF?>" method="post" autocomplete="off">

    <div >
    <table class="ds_box">
      <tr> 
        <td id="ds_calclass"> </td> 
      </tr>
    </table>
    </div>
    <script type="text/javascript" src="calendar.js"> </script> 
    <br/>
    <br/>
    <div>
    <table>
    <tr>
    <td>SR # Search :</td>
    <td><input type="text" name="op_num" id="op_num" onkeyup="getout();"></td>
    </tr>
    </table>
    </div>
    <div id="operators_report">
    <fieldset>
    <legend><h1>Supervisor's Shift Report</h1></legend>
    <div id="op_date_1">
    <label>SR# :</label>
    <input type="text" name="op_number" id="op_number" value="<?php echo $currentSR?>"  
    </div>

    <div id="op_number_1">
    <label>Date :</label>
    <input type="text" name="op_date" id="op_date" value="<?php echo $op_date?>
    </div>
    <table>
    <tr>
    <td>Section:</td>
    <td><input type="text" name="section_name" id="section_name" value="<?php echo $section_name?>" onkeydown="getmat();"></td>
    <td>Supervisor:</td>
    <td><input type="text" name="supervisor" id="supervisor" value="<?php echo $supervisor?>"  ></td>
    </tr>
    <tr>
    <td>Date: </td>
    <td><input type="text" name="process_date" id="process_date" value="<?php echo $process_date?>" onkeydown="ds_sh(this);"></td>
    <td>Shift: </td>
    <td><input type="text" name="process_shift" id="process_shift" value="<?php echo $process_shift?>" td>
    </tr>
    </table>

    </fieldset>
    </div>
    <input type="hidden" name="section_id" id="section_id" value="" />
    <input type="hidden" name="process_id" id="process_id" value="" />
    <input type="hidden" name="spv_id" id="spv_id" value="" />
    <input type="hidden" name="shift_id" id="shift_id" value="" />
    <div id="op_output_fieldset">

    </div>
    <div id='btn_spv'>
    <input type="submit" name="update" id="update" value="Update">
    </div>

    </form>
    </body>
    </html>
    get_fab_spv_process_reject_list_search.php
    PHP Code:
    <?php
    ob_start
    ();
    include 
    "connection.php";  
    $id $_POST["id"];
    if(isset(
    $id) && !empty($id)){       
        
    $display ""

        
    $sql "select DISTINCT p.process_name FROM process_list AS p JOIN spv_reject AS s ON (p.process_id = s.process_id) WHERE s.op_number LIKE '%$id%' ORDER BY p.process_id"
        
    $rsd mysql_query($sql); 
        while(
    $rs mysql_fetch_assoc($rsd)) { 
            
    $process_name[] = $rs['process_name']; 
        } 
        
    $output_array = array();   
        
    $sql "SELECT op_number, compound_type, compound_output  
        FROM spv_output WHERE op_number LIKE '%
    $id%'"
        
    $rsd mysql_query($sql); 
        while(
    $rs mysql_fetch_assoc($rsd)) { 
            
    $output_array[$rs['op_number']][$rs['compound_type']] = $rs['compound_output']; 
        } 
        
    $process_array = array();   
        
    $processID_array = array();   
        
    $sql "SELECT output_id, op_number, compound_type, compound_reject 
        FROM spv_reject WHERE op_number LIKE '%
    $id%'"
        
    $rsd mysql_query($sql); 
        while(
    $rs mysql_fetch_assoc($rsd)) { 
            
    $process_array[$rs['op_number']][$rs['compound_type']] = $rs['reject']; 
            
    $processID_array[$rs['op_number']][$rs['compound_type']]['output_id'] = $rs['output_id']; 
        } 
            
    $display .= "<tr>";
            
    $display .= "<th>Process</th>";                
            foreach (
    $process_name as $process_v){    
                
    $display .= "<th style='border:none;'><input type='text' name='process_name[]' value='$process_v' style='border:none;background-color: transparent;text-align:center;color: #FFF; font-weight: bold; '  size='15' /></th>"
            } 
            
    $display .= "</tr>";          
             
    $sql_comp "(SELECT DISTINCT r.compound_type AS compound_type FROM spv_reject AS r WHERE r.op_number LIKE '%$id%')
            UNION
            (SELECT o.compound_type AS compound_output FROM spv_output AS o WHERE o.op_number LIKE '%
    $id%') ORDER BY compound_type ASC";
            
    $res mysql_query($sql_comp); 
            if(
    mysql_num_rows($res)){ 
                while(
    $comp mysql_fetch_assoc($res)){    
                    
    $compound_type $comp['compound_type'];     
                    
    $display .= "<tr>"
                        
    $display .= "<td> 
                        <input type='text' name='compound_type[]' value='
    $compound_type' style='border:none;' /> 
                       </td>"
    ;  
                    
                                   
    $outputvalue = (array_key_exists($compound_type,$output_array[$id]) ? "{$output_array[$id][$compound_type]}"&nbsp;"); 
                        
    $display .= "<td style='border:none;'><input type='text' name='output[]' value='$outputvalue' /></td>"
            
                        foreach(
    $process_name AS $process_t){ 
                            
                                   
    $value = (array_key_exists($process_t,$process_array[$id][$compound_type]) ? "{$process_array[$id][$compound_type][$process_t]}"&nbsp;");     
                             
                                   
    $process_id = (array_key_exists($process_t,$processID_array[$id][$compound_type]) ? "{$processID_array[$id][$compound_type][$process_t]['output_id']}"NA"); 
                                 
                                
    $display .= "<td style='border:none;'><input type='text' name='process[$process_id][]' value='$value' size='7' /></td>";            
                        } 
                    
    $display .= "</tr>"
                } 
            }      

     
    ?>
        <html>
        <head>
        </head>
        <body>
              <table>
                        <?php
                        
    if(isset($display)){
                            echo 
    "$display";
                        }
                        
    ?>
                </table>
        </body>
    </html>
    I felt difficulties in using array to display my data in a table format.

    I hope somebody can help me.
    Thank you

  4. #4
    Join Date
    Jul 2013
    Location
    Voorheesville NY USA
    Posts
    550
    So why not isolate the area where you are using the array element in your html to display the contents.

    Yes - I'm way too lazy to read thru all you code. Just give us the problem you're having and perhaps we can help you out. That is - if the problem is truly in your display code and not somewhere else like you 'get' code.

    Hope you had a nice holiday, if you're in the USA.

  5. #5
    Join Date
    Oct 2013
    Posts
    29
    Have you checked the output of the get_fab_spv_process_reject_list_search.php file?

  6. #6
    Join Date
    Jul 2013
    Location
    Voorheesville NY USA
    Posts
    550
    Tell us what your concern is about using arrays (why?) to display your output. Usually people use html tables and populate it with the query result fields as they fetch them one row at a time.
    Code:
    $my_display = "<table>";
    while ($row = MySQL_fetch_array($results))
    {
      $my_display .= "<tr><td>$row['fld1']</td><td>$row['fld1']</td><td>$row['fld3']</td></tr>";
    }
    $my_display .= "</table>";
    .... and then echo the $my_display var at the appropriate place in your html.

Thread Information

Users Browsing this Thread

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

Posting Permissions

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



Recent Articles