Jump to content

html table with data from 2 sources


ohad
Go to solution Solved by requinix,

Recommended Posts

Hello

I have 2 database tables:

1) products which contain 3 columns: id, description and unit

2) units which contains 2 columns: id and description

I need to pupulate html table with data from 2 database tables.this is the structure:

id, description, unit, unit_description (the first 3 columns come from table 1 and the fourth column from table 2

I know hot to pupulate the table according to the 3 columns: (the remarks are for the 4th column that i dont know how to call). I want this column to get the description of the unit in the row from the second table in the database - using the get_unit_desc in the GlDbOra.php file (Not by making a join in the select) 

How can I do that? I'll be happy for any help

index.php

<?php
    require_once("../xxx/Includes/GlDbOra.php");
    $cursor='';
    $cursor=DBOracle::getInstance()->get_products();
?>
<html>
    <head>
        <meta charset="UTF-8">
        <title>Products</title>
        <script type="text/javascript" src="../../Bundles/php-ajax/jquery-3.5.1.js"></script>  
        <script src="../Bundles/bootstrap-4.5.0-dist/js/bootstrap.min.js"></script> 
        <link href="../Bundles/bootstrap-4.5.0-dist/css/bootstrap.min.css" rel="stylesheet" id="bootstrap-css"> 
        <link href="../xxx/css/global_style.css" type="text/css" rel="stylesheet" madia="all"/> 
    </head>
    <body>
        <div class="container">
            <div class="row">
                <div class="panel  panel-primary filterable">
                   <div class="panel-heading">
                        <h3 class="panel-title">Products</h3>
                        <div class="pull-right">
                            <button class="btn btn-default btn-xs btn-filter"><span class="glyphicon glyphicon-filter"></span> Filter</button>
                        </div>
                    </div>
                    <form id="data_form" name="datatable_form" method="POST">
                        <div class="table-repsonsive">
                            <table class="table table-bordered" id="tab_logic">                                        
                               <thead>
                                    <tr class="filters" id="table_header_2_btn">
                                        <th width="12%"><input type="text" class="form-control" name="Id[]" value="" placeholder="Id" disabled /></th>
                                        <th width="30%"><input type="text" class="form-control" name="DESCRIPTION[]" value="" placeholder="Description" disabled /></th>
                                        <th width="12%"><input type="text" class="form-control" name="UNIT[]" value="" placeholder="Unit"  disabled /></th>
<!--                                        <th width="30%"><input type="text" class="form-control" name="UNIT_DESCRIPTION[]" value="" placeholder="Description" disabled /></th> -->
                                        <th width="12%"></th>
                                    </tr>
                                </thead>
                                <tbody>
                                    <?php
                                        foreach ($cursor as $cursorCurrentRow) 
                                        {
                                            echo '<tr class="form-group">';
                                            echo "<td width=".'"12%"><input type="text" name="ID[]" value="'.htmlspecialchars($cursorCurrentRow['ID'], ENT_QUOTES).'" disabled style="border:none;"></td>';
                                            echo "<td width=".'"30%"><input type="text" name="DESCRIPTION[]" value="'.htmlspecialchars($cursorCurrentRow['DESCRIPTION'], ENT_QUOTES).'" disabled style="border:none;"></td>';
                                            echo "<td width=".'"12%"><input type="text" name="UNIT[]" value="'.htmlspecialchars($cursorCurrentRow['UNIT'], ENT_QUOTES).'" disabled style="border:none;"></td>';
//                                            echo "<td width=".'"30%"><input type="text" name="UNIT_DESCRIPTION[]" value="'.htmlspecialchars($cursorCurrentRow['DESCRIPTION'], ENT_QUOTES).'" disabled style="border:none;"></td>';
                                            echo "<td width=".'"12%">'
                                                    . '<a class='.'"add" title='.'"Add" data-toggle='.'"tooltip"><i class='.'"material-icons">&#xE03B;</i></a>'
                                                    . '<a class='.'"edit" title='.'"Edit" data-toggle='.'"tooltip"><i class='.'"material-icons">&#xE254;</i></a>'
                                                    . '<a class='.'"delete" title='.'"Delete" data-toggle='.'"tooltip"><i class='.'"material-icons">&#xE872;</i></a>'
                                                    . '</td>';
                                            echo "</tr>\n";
                                        }
                                        ?>
                                </tbody>
                            </table>
                        </div>
                    </form>
                </div>
                <button class="regular_button" id="add-new"><span class="glyphicon glyphicon-plus"></span> Add Rows</button>
                <button class="regular_button" id="save_rows"><span class="glyphicon glyphicon-floppy-save"></span> Save</button>
            </div>                
        </div>
     </body>
</html>

GlDbOra.php

<?php
    class DBOracle 
    {
        
        private static $instance = null;

        public static function getInstance() 
        {
            if (!self::$instance instanceof self) 
            {
                self::$instance = new self;
            }
            return self::$instance;
        }
        public function __clone() 
        {
            trigger_error('Clone is not allowed.', E_USER_ERROR);
        }

        public function __wakeup() 
        {
            trigger_error('Deserializing is not allowed.', E_USER_ERROR);
        }

        public function __construct () 
        {
            $databaseConfig = include 'config.php';
            $OracleUser=$databaseConfig['Oracle_User'];
            $OraclePwd=$databaseConfig['Oracle_Pwd'];
            $OracleDB=$databaseConfig['Oracle_DB']; 
            $this -> OracleUser = $OracleUser;
            $this -> OraclePwd = $OraclePwd;
            $this -> OracleDB = $OracleDB;
            $this->con = oci_connect($this->OracleUser, $this->OraclePwd, $this->OracleDB);
            if (!$this->con) {
                $e = oci_error();
                trigger_error(htmlentities($e['message'], ENT_QUOTES), E_USER_ERROR);
                exit;
            }
        }

        public function get_products() 
        {
            $cursor='';
            $query = "begin get_products(:cursor); end;";
            $stid = oci_parse($this->con, $query);
            $p_cursor = oci_new_cursor($this->con);
            oci_bind_by_name($stid, ':cursor', $p_cursor, -1, OCI_B_CURSOR);
            oci_execute($stid);
            oci_execute($p_cursor, OCI_DEFAULT);
            oci_fetch_all($p_cursor, $cursor, null, null, OCI_FETCHSTATEMENT_BY_ROW);
            oci_free_statement($stid);
            oci_close($this->con);
            return  $cursor;
        }

        public function get_unit_desc($unitid) 
        {
            $unit_desc='';
            $query = "begin :unit_desc_bv := get_unit_desc(:id_bv); end;";
            $stid = oci_parse($this->con, $query);
            oci_bind_by_name($stid, ':id_bv', $unitid);
            oci_bind_by_name($stid, ':unit_desc_bv', $unit_desc,30);
            oci_execute($stid);
            oci_free_statement($stid);
            oci_close($this->con);
            return $unit_desc;
        }
    }
?>

 

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.