Jump to content

Displaying mysql select records in html css table


hance2105
Go to solution Solved by hance2105,

Recommended Posts

hello guys i have created the below codes. the first one is the mysql select statement which works fine when i echo. the second one is an html/css table i created. i am stuck to the point where i can merge both of them so that i get a nice display and the total price of the products are calculated in each column.

 

the first code selects product name, retailer name and product price from 5 tables. using the echo codes i can display the records in columns.

 

code for mysql select statement

 

<?php session_start(); include('db_connect.php'); $username = $_SESSION['username']; $user = mysql_fetch_assoc(mysql_query("select user_id from tbllogin where username = '{$username}'")); $query = mysql_query("SELECT * FROM tblfav_ret a, tblretailer b, tblretprod c, tblproduct d, tblfavourites eWHERE a.ret_id = b.ret_idAND b.user_id = c.user_idAND c.prod_id = d.prod_idAND d.prod_id = e.prod_idAND a.user_id = '{$user['user_id']}'"); $num = mysql_num_rows($query); if($num>0){ echo "<center><table bgcolor='grey' width='80%' border=0>"; echo "<tr bgcolor='#CCCCCC'>";echo "<td><b><center>Name</td>";echo "<td><b><center>Retailer</td>";echo "<td><b><center>Price</td>";echo "</tr>"; while($row = mysql_fetch_assoc($query)){     extract($row);       echo "<tr>";     echo "<td style='text-align: center;'>".$row['prod_name']."</td>";     echo "<td style='text-align: center;'>".$row['ret_name']."</td>";echo "<td style='text-align: center;'>".$row['prod_price']."</td>";echo "</tr>";     }echo "</table>";} ?>

 

i further created this html/css table which displays smthng like this

 

product name     <retailer_name>   <retailer_name>  <retailer_name>  <retailer_name>

    prod_1                 price1                   price2                  price3                 price4

    prod_2                 price1                   price2                  price3                 price4

total                      <total_price>       <total_price>       <total_price>       <total_price>

 

 

<html>
<body>
 
<div id="myfavourites">
 
<table class="fav_tbl">
 
<thead>
            <tr>
                        <th scope="col">Product</th>
                        <th scope="col">Retailer 1</th>
                        <th scope="col">Retailer 2</th>
                        <th scope="col">Retailer 3</th>
                        <th scope="col">Retailer 4</th>
           </tr>
                </thead>
                <tfoot>
                    <tr>
                        <th scope="row">Total per month</th>
                        <td>Total 1</td>
                        <td>Total 2</td>
                        <td>Total 3</td>
                        <td>Total 4</td>
                    </tr>
                </tfoot>
 
</table>
 
</div>
 
</body>
</html>

 

the help i need is to make the display in the html/css table and calculation of total price of products listed

Link to comment
Share on other sites

  • 3 weeks later...
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.