mysql query - edit extra fields - php

I have 3 TABLES products, products_extra_fields, products_to_products_extra_fields
products TABLE
+-------------+--------------+---------------+
| products_id | categories_id| products_name |
+-------------+--------------+---------------+
| 1 | 1 | product 1 |
| 2 | 1 | product 2 |
+-------------+--------------+---------------+
products_extra_fields TABLE
+--------------------------+---------------------------+
| products_extra_fields_id | products_extra_fields_name|
+--------------------------+---------------------------+
| 1 | sugar |
| 2 | cocoa |
| 3 | butter |
| 4 | milk |
+--------------------------+---------------------------+
products_to_products_extra_fields TABLE
+-------------+---------------------------+-----------------------------+
| products_id | products_extra_fields_id | products_extra_fields_value |
+-------------+---------------------------+-----------------------------+
| 1 | 1 | 20% |
| 1 | 2 | 45% |
| 1 | 3 | 27% |
| 2 | 1 | 12% |
+-------------+---------------------------+-----------------------------+
I wanna edit product 1 I use this query:
SELECT
products_name,
products_extra_fields_name,
products_extra_fields_value FROM products, products_extra_fields, products_to_products_extra_fields
WHERE products_to_products_extra_fields.products_extra_fields_id = products_extra_fields.products_extra_fields_id AND
products_to_products_extra_fields.products_id=1
GROUP BY products_extra_fields.products_extra_fields_id;
+---------------+---------------------------+----------------------------+
| products_name | products_extra_fields_name| products_extra_fields_value|
+---------------+---------------------------+----------------------------+
| product 1 | sugar | 20% |
| product 1 | cocoa | 45% |
| product 1 | butter | 27% |
+---------------+---------------------------+----------------------------+
But I wanna see
products_extra_fields_name (milk) with no value
+---------------+---------------------------+----------------------------+
| products_name | products_extra_fields_name| products_extra_fields_value|
+---------------+---------------------------+----------------------------+
| product 1 | sugar | 20% |
| product 1 | cocoa | 45% |
| product 1 | butter | 27% |
| product 1 | milk | |
+---------------+---------------------------+----------------------------+
and for product 2 cocoa, butter, milk with no value only sugar 12%
What can I do to get the results I want.
look at my php script (products_edit2.php?id=1 or 2 )
<?php
require ('mysql/mysql_connect.php'); // Connect to the database.
if (is_numeric ($_GET['id']) ) {
$query = "SELECT
products_name, products_extra_fields_name, products_extra_fields_value FROM
products, products_extra_fields, products_to_products_extra_fields WHERE
products_to_products_extra_fields.products_extra_fields_id = products_extra_fields.products_extra_fields_id AND
products_to_products_extra_fields.products_id = {$_GET['id']}
GROUP BY products_extra_fields.products_extra_fields_id";
if ($result = mysql_query ($query)) {
$query2 = "SELECT products_name FROM products WHERE products_id={$_GET['id']}";
if ($result2 = mysql_query ($query2)) {
$row2 = mysql_fetch_array ($result2);
$products_name = $row2['products_name'];
?>
<form action='products_edit.php' enctype='multipart/form-data' method='POST'>
<table width="50%" border="0" cellpadding="2" cellspacing="2">
<tr>
<td width="20%" align="right">PRODUCTS NAME:</td>
<td><input type="text" name="products_name" size="80" value="<?php echo $products_name; ?>" /></td>
</tr>
<?php
}
/***** ***** *****/
while ($row = mysql_fetch_assoc ($result)) {
$products_extra_fields_name = $row['products_extra_fields_name'];
$products_extra_fields_value = $row['products_extra_fields_value'];
$products_extra_fields_id = $row['products_extra_fields_id'];
?>
<tr>
<td width="20%" align="right"><?php echo $products_extra_fields_id .'-'. $products_extra_fields_name; ?></td>
<td><input type="text" name="categories_name" size="80" value="<?php echo $products_extra_fields_value; ?>" /></td>
</tr>
<?php }
/***** ***** END *****/
?>
<input type="hidden" name="categories_id" size="10" value="<?php echo $_GET['id']; ?>" />
<tr>
<td width="100%" colspan="2" align="right"><input type="submit" name="submit" value="SAVE"/></td>
</tr>
</table>
</form>
<?php
} else { // Couldn't get the information.
print "<p>Could retrieve the entry because: <b>" . mysql_error() . "</b><br/><br/>. The query was $query.</p>";
}
}else{ // No ID set.
print '<p><b>You must have made a mistake in using this page.</b></p>';
}
?>
</body>
</html>
I wanna see all 4 products_extra_fields_name and 4 input box (product 1 have 3 value 1 null, product 2 have 1 value 3 null)

When you use a comma separated list in FROM, MySQL uses an Inner Join. To get what you want, you need to use a Left Join.
SELECT
products_name,
products_extra_fields_name,
products_extra_fields_value
FROM products, products_extra_fields
LEFT JOIN products_to_products_extra_fields
ON products_to_products_extra_fields.products_extra_fields_id = products_extra_fields.products_extra_fields_id
AND products_to_products_extra_fields.products_id=1
GROUP BY products_extra_fields.products_extra_fields_id;
This should produce:
+---------------+---------------------------+----------------------------+
| products_name | products_extra_fields_name| products_extra_fields_value|
+---------------+---------------------------+----------------------------+
| product 1 | sugar | 20% |
| product 1 | cocoa | 45% |
| product 1 | butter | 27% |
| product 1 | milk | NULL |
+---------------+---------------------------+----------------------------+

Related

How to echo results from SQL table correctly using JOIN operator?

I have two tables:
Clubs
|---------------------|------------------|
| id | name |
|---------------------|------------------|
| 1 | Arsenal |
|---------------------|------------------|
| 2 | Chelsea |
|---------------------|------------------|
| 3 | Fulham |
|---------------------|------------------|
| 4 | Leeds |
|---------------------|------------------|
Matches
|---------------------|------------------|------------------|
| id | home | away |
|---------------------|------------------|------------------|
| 1 | 1 | 3 |
|---------------------|------------------|------------------|
| 2 | 2 | 4 |
|---------------------|------------------|------------------|
Explanation: the numbers in the columns "home" and "away" in the Matches table linking to the the id in de Clubs table.
Now I want to echo (with php) the following:
|---------------------|------------------|
| home | away |
|---------------------|------------------|
| Arsenal | Fulham |
|---------------------|------------------|
| Chelsea | Leeds |
|---------------------|------------------|
Explanation: when clicking on the teamname I want to open the club.php page with the teaminfo.
I've tried the following:
<?php
$sql = "SELECT * FROM matches JOIN clubs ON matches.home AND matches.away = clubs.id"
$rs_result = $conn->query($sql);
?>
<div style="overflow-x:auto">
<table>
<tr><th><strong>Home</strong></th><th><strong>Away</strong></th><tr>
<?php
while($row = $rs_result->fetch_assoc()) {
?>
<tr>
<td><? echo $row['home']; ?></td>
<td><? echo $row['away']; ?></td>
</tr>
<?php } ?>
</table></div>
It is echoing the following:
|---------------------|------------------|
| home | away |
|---------------------|------------------|
| 1 | 3 |
|---------------------|------------------|
| 2 | 4 |
|---------------------|------------------|
My question: How can I show the clubnames in the table but passing the club id in the "a href" link?
I've tried $row[1] and so on but it doesnt work. Which SQL statement do I need? JOIN? INNER JOIN? LEFT JOIN?
Many thanks in advance!
I believe this should work - I made an adjustment to your query.
You can use left joins when you are interested in the left side of the query (matches) and do not care if the clubs have not been populated. F ex if you have a home - away of 1 and 5. We know that 1 is Arsenal but there is no entry for 5 in clubs.
Left join will display it, inner join will not.
<?php
$sql = "SELECT home,away,homeclub.name as homename,awayclub.name as awayname FROM matches
JOIN clubs as homeclub ON matches.home = homeclub.id
JOIN clubs as awayclub ON matches.away = awayclub.id"
$rs_result = $conn->query($sql);
?>
<div style="overflow-x:auto">
<table>
<tr><th><strong>Home</strong></th><th><strong>Away</strong></th><tr>
<?php
while($row = $rs_result->fetch_assoc()) {
?>
<tr>
<td><? echo $row['homename']; ?></td>
<td><? echo $row['awayname']; ?></td>
</tr>
<?php } ?>
</table>
</div>

Fetching/Putting 2 variables in a mysqli_num_row and mysqli_fetch_array in PHP

Basically I want to do a search by category and title. My problem is that the two are located in separate tables. I was thinking of putting 2 variables in the mysqli_num_rows or mysqli_fetch_array but I don't think it's the right idea. The $search variable is working already but I don't know what I will do for $searchcat that is a different table.
<table border="1">
<tr>
<th>ID</th>
<th>Survey Title</th>
<th>Category</th>
</tr>
<?php
if (isset($_POST['submit']))
{
include 'testdb.php'; //connection is written in other page (db.php)
$var =$_POST['search'] ;
$searchtype = $_POST['searchtype'];
$my_query="SELECT s.survey_id, s.title,c.categoryname
FROM survey_header as sh
JOIN survey AS s ON sh.survey_id=s.survey_id
JOIN category AS c ON sh.category_id=c.category_id
WHERE $searchtype LIKE '%".$var."%'
ORDER BY title ASC";
$get_data= mysqli_query($con, $my_query) or die ("Couldn't execute query: ".mysqli_error());
if (mysqli_num_rows($get_data) > 0 )
{
echo "<h3>Search results:</h3>";
while($show = mysqli_fetch_array($get_data))
{
$id = $show['survey_id'];
$title = $show['title'];
$category = $show['categoryname']; //
echo "<tr align='center'>";
echo "<td><font color='black'>" .$id. "</font></td>";
echo "<td><font color='black'>" .$title. "</font></td>";
echo "<td><font color='black'>" .$category. "</font></td>";
}
}
else{
echo "No Records found!";
}
}
?>
</table>
</body>
This is table category (categoryname is what I need)
+-------------+---------------+-------------+
| category_id | categoryname | datecreated |
| 1 | Philosophical | |
| 4 | Political | |
| 6 | Social | |
This is table survey (title is all I need)
| 1 | survey_id | title | description | duration | gender | age_group_from | age_group_to |
| 2 | 44 | game1 | description1 | 5 | male | 0 | 18 |
| 3 | 45 | game2 | description2 | 25 | female | 18 | 25 |
| 4 | 46 | game3 | description3 | 89 | female | 26 | 35 |
This is table survey_header (survey_id and category_id is what I need)
| 1 | survey_id | date_created | date_updated | opening_date | closing_date | category_id | topic_id |
| 2 | 33 | Not important | Not important | NULL | NULL | 1 | NULL |
| 3 | 45 | Not important | Not important | NULL | NULL | 6 | NULL |
| 4 | 46 | Not important | Not important | NULL | NULL | 4 | NULL |
Try this query :
$my_query="SELECT s.survey_id, s.title,c.categoryname
FROM survey_header as sh
JOIN survey AS s ON sh.survey_id=s.survey_id
JOIN category AS c ON sh.category_id=c.category_id
WHERE $searchtype LIKE '%".$var."%'
ORDER BY title ASC";
$get_data= mysqli_query($con, $my_query) or die ("Couldn't execute query: ".mysqli_error());
if (mysqli_num_rows($get_data) > 0 )
{
/*create table*/
}
else
// do something else

display table group by category using php

my database design is like this
-- Table Reason
--------------------------
| reasonid | reasonname |
--------------------------
| 1 | reason1 |
| 2 | reason2 |
--------------------------
-- Table Student
----------------------------
| studentid | studentname |
----------------------------
| 1 | John |
| 2 | Jane |
| 3 | Hulk |
----------------------------
-- Table form
-----------------------------------
| formid | studentid | reasonid |
-----------------------------------
| 1 | 1 | 1 |
| 2 | 2 | 2 |
| 3 | 3 | 1 |
-----------------------------------
I want to show data table like :
reason1
| 1 | John |
| 2 | Hulk |
reason2
| 1 | Jane |
I have tried below code but the result is not groupBy reason
<?php $i =1;
while($rowfet = mysql_fetch_array($myselect)){ ?>
<h2><?php echo $rowfet['ReasonName']; ?></h2>
<table>
<thead>
<tr class="active">
<th>No.</th>
<th>StudentName</th>
</tr>
</thead>
<tbody>
<tr>
<td align="center"><?php echo $i; ?></td>
<td><?php echo $rowfet['STUDENTNAME']; ?></td>
</tr>
</tbody>
</table>
<?php $i++; } ?>
the result of this code is :
reason1
| 1 | John |
reason1
| 2 | Hulk |
reason2
| 3 | Jane |
You could do something like this:
outside while loop:
$lastReasonId = '';
inside while loop:
if($rowfet['reasonid'] != $lastReasonId){
// show heading
}
$lastReasonId = $rowfet['reasonid'];
But your code is far from ok. The $i++ thing is not doing anything, you should probably echo $rowfet['studentid'] there.
And you are using deprecated mysql code.

PHP/MySql taking value from two different tables

I have a form
http://s12.postimg.org/5lylvp2h9/Untitled.png
table products
+----+---------------+
| id | product |
+----+---------------+
| 1 | pencil |
| 2 | Eraser |
| 3 | Brush |
| 4 | teddy bear |
| 5 | panda |
| 6 | kaleidoscope |
+----+---------------+
table suppliers
+----+------------------+
| id | Suppliers |
+----+------------------+
| 1 | Silberauto , Ltd.|
| 2 | MADATA , Ltd. |
| 3 | Omnitel , Ltd. |
| 4 | Profito IT Ltd. |
| 5 | Arfix , Ltd. |
+----+------------------+
table product_supplier
+------------+-------------+-----------+
| product_id | supplier_id | unit_cost |
+------------+-------------+-----------+
| 4 | 1 | 10.50 |
| 2 | 5 | 15.25 |
| 1 | 2 | 20.40 |
| 3 | 3 | 25.75 |
| 5 | 3 | 30.00 |
| 5 | 4 | 35.75 |
| 1 | 1 | 40.55 |
| 4 | 3 | 45.75 |
| 2 | 2 | 50.15 |
| 3 | 5 | 55.10 |
| 6 | 2 | 60.00 |
| 9 | 2 | 65.55 |
| 7 | 4 | 70.85 |
| 9 | 3 | 75.35 |
| 8 | 1 | 80.20 |
+------------+-------------+-----------+
In my form select field I'm selecting an item(pencil) from table products. each item has an unique value which references to item id(table products -> id).
In radio select I'm selecting supplier(from table suppliers). radio button has value(in this example MADATA,UAB) and name(item id. in this example 7)
In next field price I want to print unit_cost from table product_suplier where product_id(it is my value from select field.) is equal to supplier (from table suppliers).
in kaina.php my condition
SELECT unit_cost
FROM product_supplier, suppliers
WHERE product_id= :product_id AND suppliers.suppliers = :suppliers');
$stmt->execute(array('supplier' => $supplier,'product_id' => $product_id));
while($row = $stmt->fetch()) {
echo $row['unit_cost']." LT ";
}
is bad. in this example it prints two values. how to change SELECT condition to take one value, not two(becouse there are two supliers who sells the same item).
my code:
index.php
<?
$username='root';
$password='pass';
try {
$conn = new PDO('mysql:host=localhost;dbname=univer', $username, $password);
$conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
} catch(PDOException $e) {
echo 'KLAIDA: ' . $e->getMessage();
}?>
<html>
<head>
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script>
<link rel='stylesheet' type= 'text/css' href='css/styles.css'>
<link rel='stylesheet' type= 'text/css' href='css/bootstrap.css'>
<script>
function tiekejai(tiekejas){
$.ajax({
type: "POST",
url: "tiekejai.php?q="+supplier,
dataType: "html",
success: function(duomenys){
$("#tiekejai").html(duomenys);
}
});
};
function kaina(tiekejas,data){
$.ajax({
type: "POST",
url: "kaina.php?supplier="+supplier+"&product_id="+data,
dataType: "html",
success: function(duomenys){
$("#kaina").html(duomenys);
}
});
};
</script>
</head>
<body>
<main id="content" role="content">
<div id="forma">
<form class="form-horizontal">
<fieldset>
<legend>Uzsakymo forma</legend>
<div class="control-group">
<label class="control-label" for="selectbasic">Pasirinkite preke</label>
<div class="controls">
<select id="selectas" name="selectas" class="input-xlarge"
onchange="tiekejai(this.value)">
<?php
$data = $conn->query('SELECT * FROM products
INNER JOIN product_suplier
ON products.id = product_suplier.product_id
GROUP BY product');
foreach($data as $row) {
echo "<option value=".$row['product_id'].">".$row['product']."</option>";
}
?>
</select>
</div><!--.controls -->
</div><!--.control-group -->
<div class="control-group">
<label class="control-label" for="radios">Pasirinkite tiekeja</label>
<div class="controls" id="tiekejai">
</div>
</div>
<div class="control-group">
<label class="control-label" for="radios">kaina</label>
<div class="controls">
<span class="uneditable-input" id="kaina">Prekes kaina</span>
</div>
</div>
<div class="control-group">
<label class="control-label" for="textinput">Kiekis</label>
<div class="controls">
<input id="textinput" name="textinput" placeholder="max 40" class="input-xlarge" type="text">
</div>
</div>
<div class="control-group">
<label class="control-label" for=""></label>
<div class="controls">
<button id="" name="" class="btn btn-primary">Uzsakyti</button>
</div>
</div>
</fieldset>
</div>
</main>
<script>
document.getElementById("selectas").selectedIndex = -1;
</script>
</body>
</html>
tiekejai.php
<?php
$q=$_GET["q"];
$con = mysql_connect('localhost', 'root', 'pass');
if (!$con){
die('Could not connect: ' . mysql_error());}
mysql_select_db("univer", $con);
$sql=" SELECT * FROM suppliers
INNER JOIN product_suppliers
ON tiekejai.id = product_suppliers.product_id
WHERE product_suppliers.product_id= '".$q ."'";
$result = mysql_query($sql);
while($row = mysql_fetch_array($result)){
echo "<label class='radio'>";
echo "<input name='". $q ."' id=radios
value= '". $row['supplier'] ."'
type='radio' onchange='kaina(this.value,this.name)'>";
echo $row['supplier'];
echo "</label>";
}
mysql_close($con);
?>
kaina.php
<?php
$supplier = $_GET['supplier'];
$product_id = $_GET['product_id'];
$username='root';
$password='pass';
try {
$conn = new PDO('mysql:host=localhost;dbname=univer', $username, $password);
$conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
$stmt = $conn->prepare('
SELECT unit_cost
FROM product_supplier, suppliers
WHERE product_id= :product_id AND suppliers.suppliers = :suppliers');
$stmt->execute(array('supplier' => $supplier,'product_id' => $product_id));
while($row = $stmt->fetch()) {
echo $row['unit_cost']." LT ";
}
}
catch(PDOException $e) {
echo 'KLAIDA: ' . $e->getMessage();
}
?>
I think going back and forth from Lithuanian to English is confusing both you and us. Can we do the whole thing in English for now? So that data set might look like this...
products
+----+---------------+
| id | product |
+----+---------------+
| 1 | pencil |
| 2 | Eraser |
| 3 | Brush |
| 4 | teddy bear |
| 5 | panda |
| 6 | kaleidoscope |
+----+---------------+
suppliers
+----+------------------+
| id | Suppliers |
+----+------------------+
| 1 | Silberauto , Ltd.|
| 2 | MADATA , Ltd. |
| 3 | Omnitel , Ltd. |
| 4 | Profito IT Ltd. |
| 5 | Arfix , Ltd. |
+----+------------------+
product_supplier
+------------+-------------+-----------+
| product_id | supplier_id | unit_cost |
+------------+-------------+-----------+
| 4 | 1 | 10.50 |
| 2 | 5 | 15.25 |
| 1 | 2 | 20.40 |
| 3 | 3 | 25.75 |
| 5 | 3 | 30.00 |
| 5 | 4 | 35.75 |
| 1 | 1 | 40.55 |
| 4 | 3 | 45.75 |
| 2 | 2 | 50.15 |
| 3 | 5 | 55.10 |
| 6 | 2 | 60.00 |
| 9 | 2 | 65.55 |
| 7 | 4 | 70.85 |
| 9 | 3 | 75.35 |
| 8 | 1 | 80.20 |
+------------+-------------+-----------+
Note: I got rid of the id column on the product_supplier table because it appears to serve no purpose.
Now, what's the problem?

How to echo specific data in loop with a condition specific to the last row

For an accounting system, I'm using PHP & MySQL. I've two tables "GROUP" and "ACHEADS".
In the GROUP table, I have:
---------------------
| id (AI) | group |
---------------------
| 1 | Group 1 |
| 2 | Group 2 |
---------------------
In the ACHEADS table, I have:
-----------------------------------------
| id (AI) | ac_head | amount | j_id |
-----------------------------------------
| 1 | Something 1 | 2000 | 1 |
| 2 | Something 2 | 1000 | 1 |
| 3 | Something 3 | 5000 | 2 |
| 4 | Something 4 | 4000 | 2 |
| 5 | Something 5 | 8000 | 2 |
-----------------------------------------
I've joined the two tables as GROUP.id <<->> ACHEADS.j_id
Now I need to preview the data like this:
----------------------------------------------
Particulars | Details | Total |
----------------------------------------------
Group 1 | | |
Something 1 | 2000 | |
Something 2 | 1000 | 3000 |
----------------------------------------------
Group 2 | | |
Something 3 | 5000 | |
Something 4 | 4000 | |
Something 5 | 8000 | 17000 |
----------------------------------------------
GRAND TOTAL | | 20000 |
------------------------------------==========
Challenges
The table will be dynamic and will generate within a PHP loop (I'm
using a WHILE loop)
Remember: it's a table and if I miss echoing a td, then the table will break up
Problems
When I'm using the loop it's echoing the data on the Details td
accurately. But the sum of the details row according to j_id is also
echoing in each td
Preview here:
----------------------------------------------
Particulars | Details | Total |
----------------------------------------------
Group 1 | | |
Something 1 | 2000 | 3000 |
Something 2 | 1000 | 3000 |
----------------------------------------------
Group 2 | | |
Something 3 | 5000 | 17000 |
Something 4 | 4000 | 17000 |
Something 5 | 8000 | 17000 |
----------------------------------------------
My thoughts
If I can check whether it is the last data of the query, if isset,
then echo the total amount with it's td. (But remember the
Challenge#2)
Does it require a foreach loop?
I failed
I tried checking max(id), it works fine in SQL, but can't use it in
condition within a loop.
(If you still can't understand me, then on the second phase, I'll post my code.)
I would do 2 loops:
Fetch id from GROUP
Fetch amount from ACHEADS based on j_id
This would look something like (non-tested code):
echo '<table><tr><td>Particulars</td><td>Details</td><td>Total</td></tr>';
$total = 0;
$q1 = "SELECT id FROM `GROUP`";
$res1 = mysqli_query($q1);
while($row1 = mysqli_fetch_assoc($res1)) {
echo
$group_total = 0;
$j_id = $row1[id];
$q2 = "SELECT ac_head, amount FROM ACHEADS WHERE j_id = $j_id";
$res2 = mysqli_query($q2);
while($row2 = mysqli_fetch_assoc($res1)) {
echo '<tr><td>' . $row2[ac_head] . '</td>';
echo '<td>' . $row2[amount] . '</td></tr>';
$group_total = $group_total + $row2[amount];
$total = $total + $row[amount];
}
echo '<tr><td colspan="3" align="right">' . $group_total . '</td></tr>';
}
echo '<tr><td>GRAND TOTAL</td>';
echo '<td colspan="2" align="right">' . $total . '</td></tr>';
echo "</table>";
njk rockz!
It worked nicely. Thanks a lot, brother - it helped me a lot, I can't explain.
Here is my final code:
<tr style="background: #000; color:#fff;">
<th style="width:150px;">Particulars</th>
<th>Details</th>
<th>Amount</th>
</tr>
<tr>
<td>Opening Balance</td>
<td></td>
<td>500000</td> <!-- till not dynamic -->
</tr>
<?php
$total = 0;
$se = "SELECT * FROM group";
$res = mysql_query($se) or die (mysql_error());
while ($row = mysql_fetch_array($res))
{
?>
<tr>
<td colspan="3" style="font-weight:bold;"><?php echo $row['group']; ?></td>
</tr>
<tr>
<?php
$group_total = 0;
$se1 = "SELECT ac_head, amount FROM `acheads` WHERE `j_Id` = '".$row['id']."'";
$res1 = mysql_query($se1) or die (mysql_error());
while ($row1 = mysql_fetch_array($res1))
{
$group_total = $group_total + $row1['amount'];
?>
<td><?php echo $row1['ac_head']; ?></td>
<td><?php echo $row1['amount']; ?></td>
<td> </td>
</tr>
<?php
}
echo '<tr><td colspan="3" align="right">' . $group_total . '</td></tr>';
}
?>
</table>
</code>

Categories