Friday, 28 December 2018

get data from sql by join two table

Using This code you can join two table for fetching data from mysql.
mysql data and table details :
hostname : localhost
dbusername : dbusername
dbpassword : yourpassword
dbname : dbname
Table Details :
Table 1 : wp_users ( column name : ID , user_login )
Table 2 : user_transactions ( column : user_id , referral_amnt )

Just copy and paste this code and modify mysql and table details as per your details

<?php
 $connect = mysqli_connect("localhost", "investment_new", "yourpassword", "investment_wp");
 $sql = "SELECT * FROM wp_users INNER JOIN user_transactions ON wp_users.ID = user_transactions.user_id";
 $result = mysqli_query($connect, $sql);
 ?>
 <!DOCTYPE html>
 <html>
      <head>
           <title>Mapplefinance Referral Amount</title>
           <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.2.0/jquery.min.js"></script>
           <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css" />
           <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/js/bootstrap.min.js"></script>
      </head>
      <body>
           <br />
           <div class="container" style="width:980px;">
<Img src="https://www.mapplefinance.com/wp-content/uploads/2018/12/transparent-logo-1-1.png"width="150px" height="150px"><br>
                <h3 align="">Mapplefinance Total Referral Amount</h3><br />               
                <div class="table-responsive">
                     <table class="table table-striped">
                          <tr>
                               <th>User Name</th>
                               <th>Referral Amount</th>
                             
                          </tr>
                          <?php
                          if(mysqli_num_rows($result) > 0)
                          {
                               while($row = mysqli_fetch_array($result))
                               {
                          ?>
                          <tr>
                               <td><?php echo $row["user_login"];?></td>
                               <td><?php echo $row["referral_amnt"]; ?></td>
                             
                          </tr>
                          <?php
                               }
                          }
                          ?>
                     </table>
                </div>
           </div>
           <br />
      </body>
 </html>

No comments:

Post a Comment