Hi in the below i want to show Consultation Charges values for that i took the td.But in that td not displying anything even td also not showing.
After executing this query i want to find the no. of rows based on the rows i want to display the data.
My expected output:
Bill Particular Bill Sub Particular Doctor Date Dis. Amt.
Consultation Charges:
all the values based on no of rows.
php
<table width="100%">
<th>Bill Particular</th>
<th>Bill Sub Particular</th>
<th>Doctor</th>
<th>Date</th>
<th>Dis. Amt.</th>
<th>Charge</th>
<th>No. of Times</th>
<th>Amount</th>
</table>
<tr><th colspan=2>Consultation Charges:</th>
<?php
$div_options = array();
$sql = "SELECT ibp.ipd_bp_id, ibp.bp_id, bp.bp_name, ibp.bsp_id, bsp.bsp_name, ibp.doctor_id, ab.employee_name doctor, ibp.date date, ibp.amount charge, ibp.discount_amount discount, ibp.no_of_time, (ibp.no_of_time * ibp.amount) total_amount
FROM bill_particular_master bp
INNER JOIN ipd_bill_particular ibp ON ibp.bp_id = bp.bp_id
LEFT OUTER JOIN bill_sub_particular bsp ON bsp.bsp_id = ibp.bsp_id
LEFT OUTER JOIN address_book ab ON ab.employee_id = ibp.doctor_id
WHERE ibp.ipd_reg_no = '$ipd_no'
AND bsp.consultant =1
AND bsp.package = 0
AND bsp.admission = 0
AND bp.bp_name != 'Scan Charges'
AND bp.bp_name !='Procedure'";
$sth = $dbh->query($sql);
//$row=$dbh->fetch();
$i=1;
while($row=$sth->fetch(PDO::FETCH_ASSOC)){
$sub_arr['bp_name'] = $row['bp_name'];
$sub_arr['bsp_name'] = $row['bsp_name'];
echo "<tr>
<td>Here is the text - " . $sub_arr['bp_name'] . "</td>
<td>The ID of the text is - " .$sub_arr['bsp_name'] . "</td>";
if($i !== 0) {
echo "<td>The ID of the previous entry is - " .$sub_arr['bp_name'] . "</td>";
}
else {
echo "<td> </td>";
}
echo "</tr>";
$i = $row['bp_name'];
}
?>
</tr>
echo "<td>The ID of the previous entry is - " . $row['bp_name'] . "</td>";
You have there variable thats not even defined in your code.
Related
I have created a database and and its tables. Insertion has done successfully. Now I want to get data from two tables using left join.
The problem is some fields which are not matching are empty. I want to remove the empty fields and to show the matching fields data.
How can I do this?
My code is:
<?php
include 'connection.php';
//joining of two table column
$sql = "select * from oc4e_product left join item ON item.Description = oc4e_product.model";
$result = mysqli_query($conn, $sql);
echo "<table border = 1px>";
echo "<tr>
<th>S/No</th>
<th>Web Name</th><th>POS Name</th> <th>POS Name</th></tr>";
$i=1;
if (mysqli_num_rows($result) > 0) {
while ($row = mysqli_fetch_array($result)) {
echo "<tr><td>" . $i . "</td>
<td>".$row['model'] ."</td>
<td>". $row['Description'] . "</td>
</tr>";
$i++;
}
}
echo "</table>";
?>
Maybe you need to modify your sql query:
//joining of two table column
$sql = "select * from oc4e_product left join item ON item.Description = oc4e_product.model where item.Description <> ''";
In this query i added filter not empty record item.Description <> ''
I have at the moment 2 results in my MySQL Database with same user_id and I want echo all in my HTML table with PDO, but it shows everytime only 1 result, not all.
<?php
$querytest = "SELECT o.output_valu,
p.amount,
p.amount_all,
p.order_id,
p.datetime
FROM allusers a
INNER JOIN order_history o
ON a.account_number = o.account_number
INNER JOIN paymentall p
ON o.output_vl_id = p.output_vl_id
WHERE a.account_number = :account_num
ORDER BY p.datetime";
$statementtest = $conn->prepare($queryoutgo);
$statementtest->bindParam(':account_num', $account_num);
$statementtest->execute();
$test_result = $statementtest->fetchAll();
foreach ($test_result as $row) {
$outputtest = $row['output_valu'];
}
?>
<table>
<tr>
<th>Test</th>
</tr>
<tr>
<td><?php echo $outputtest; ?></td>
</tr>
</table>
With print_r($test_result); it shows my 2 results in array, but why not with my code?
I worked always with mysqli not PDO in the past, maybe someone here can help me :)
In your foreach block you overwrite $outputtest every iteration. This means only the last result will be displayed. Depending on if you want to show each result on a separate row or if you want all the results together in one cell, you should either create the cells in the foreach or concatenate all the results together.
EDIT:
What I think you want is this:
$querytest = "SELECT o.output_valu, p.amount, p.amount_all, " .
"p.order_id, p.datetime " .
"FROM allusers a inner join order_history o " .
"ON a.account_number = o.account_number " .
"INNER JOIN paymentall p " .
"ON o.output_vl_id = p.output_vl_id " .
"WHERE a.account_number =:account_num " .
"ORDER BY p.datetime ";
$statementtest = $conn->prepare($queryoutgo);
$statementtest->bindParam(':account_num', $account_num);
$statementtest->execute();
$test_result = $statementtest->fetchAll();
?>
<table>
<tr>
<th>Test</th>
</tr>
<?php foreach($test_result as $row) { ?>
<tr><td><?= $row['output_valu']; ?></td></tr>
<?php } ?>
</table>
I have 3 tables i want to display the 3 table data in single table based on primary key, foreign key the result came perfectly! But i need to calculate rank based on the total marks from my second table.
result screenshot:
Please anyone tell me the query to calculate rank
I used the following mysql query
if(isset($_POST['submit']))
{
$result = mysqli_query($con,"
SELECT s.student_name
, s.contact_number
, m.total
, m.rank
, p.father_name
FROM student_details s
JOIN mark m
ON s.student_id = m.student_id
JOIN parents_details p
ON p.student_id = s.student_id
WHERE s.student_name = '".$_POST['student_name']."'
");
echo "<table border='1' align='center' cellpadding='15' bgcolor='#FFFFFF'>
<tr>
<th>NAME</th>
<th>CONTACT NUMBER</th>
<th>TOTAL MARK</th>
<th>RANK</th>
<th>FATHER NAME</th>
</tr>";
while($row = mysqli_fetch_array($result))
{
echo "<tr>";
echo "<td>" . $row['student_name'] . "</td>";
echo "<td>" . $row['contact_number'] . "</td>";
echo "<td>" . $row['total'] . "</td>";
echo "<td>" . $row['rank'] . "</td>";
echo "<td>" . $row['father_name'] . "</td>";
echo "</tr>";
}
echo "</table>";
mysqli_close($con);
}?>
SELECT * FROM
(
SELECT #rank := #rank+1 finalrank,ZZ.* FROM
(
SELECT student_details.student_name,
student_details.contact_number, mark.total,
mark.rank, parents_details.father_name
FROM student_details
INNER JOIN mark ON student_details.student_id=mark.student_id
INNER JOIN parents_details ON parents_details.student_id=student_details.student_id ,(SELECT #rank:=0)z
ORDER BY mark.total desc
)ZZ
)ZZZ
WHERE ZZZ.student_name = '".$_POST['student_name']."'
Just try above query.
Here I had used SELECT #rank:=0 and #rank := #rank+1.
I need to display an html table with data from two different tables, invoices and lineitems where invoices.id=lineitems.invoiceid. However, each row in invoices can have several lineitem rows that connect to it as invoices is the customers' order and lineitems is the table containing all the products for each order. I need to sum up the values from lineitems.quantity for every row where the invoiceid is the same so my html table can display the total quantity for the order. Is there a way to do that within my select statement for my html table?
Right now, when I display my table, I get the same invoice order listed repeatedly for each lineitem row associated with it (where the only html table column data that's different per row is the quantity).
MySQL SELECT statement:
$sql = "SELECT invoices.id, invoices.orderdate, invoices.stagestatus, FORMAT(TRIM(LEADING '$' FROM invoices.totalprice), 2) AS totalprice, clients.company, lineitems.invoiceid, FORMAT((lineitems.width * lineitems.height) /144, 2 ) AS sqft, lineitems.quantity AS qty, FORMAT((invoices.totalprice / ((lineitems.width * lineitems.height) /144)), 2) as avgsqftrevenue, FORMAT((TRIM(LEADING '$' FROM invoices.totalprice) / lineitems.quantity), 2) AS avgunitrevenue
FROM clients
INNER JOIN invoices ON clients.id = invoices.clientid
INNER JOIN lineitems ON invoices.id = lineitems.invoiceid
WHERE invoices.orderdate BETWEEN '".$revenuefrom."' AND '".$revenueto."' AND invoices.stagestatus IN (". implode(',', array_map(function($item) {return '"' . $item . '"'; }, $revenue_check)) .")
ORDER BY invoices.id DESC";
//Display daterange and table.
echo 'Displaying results for: '.$revenuefrom.' to '.$revenueto.'. '.'<BR><BR><BR>';
$result = $conn->query($sql);
echo "<table id='revenueReportA' align='center' class='report_DT'>
<tr>
<th>Customer</th>
<th>Stage Status</th>
<th>SG</th>
<th>Revenue</th>
<th>SQ FT</th>
<th>AVG Revenue Per SQ FT</th>
<th>Number of Units</th>
<th>AVG Revenue Per Unit</th>
</tr>";
if ($result = $conn->query($sql)) {
// fetch associative array
while ($row = $result->fetch_assoc()) {
echo "<tr>";
echo "<td>" . $row['company'] . "</td>";
echo "<td>" . $row['stagestatus'] . "</td>";
echo "<td>" . $row['id'] . "</td>";
echo "<td>" ."$". $row['totalprice'] . "</td>";
echo "<td>" . $row['sqft'] ." ". "ft<sup>2</sup>". "</td>";
echo "<td>" ."$". $row['avgsqftrevenue'] . "</td>";
echo "<td>" . $row['qty'] . "</td>";
echo "<td>" ."$". $row['avgunitrevenue'] . "</td>";
echo "</tr>";
}
echo "</table>";
NOTE: Due to the pre-existing code design (I inherited...), setting up a trigger is not an option and trying to run the calculation and insert that value into another column in invoices is seeming impossible from the application side (again due to the way the previous programmer designed the update/insert for invoices and lineitems). If anyone is curious about that code, please refer to the following link where I asked how complete this same task via the application side:
get sum() value from user input going into one table and store in another table using php
Any suggestions are greatly appreciated as I have tried several different methods for achieving the desired outcome.
Thank you!
Sorry if I do something wrong it is my first time using stackflow and just beginning php and mysql.
The problem I am getting is that the table updates AFTER it echos. I would like to display the updated table.
while($row = mysql_fetch_array($result)) {
$bids = $row['bids'];
$bids +=1;
mysql_query("UPDATE items SET bids = " .$bids.", cost=" . $price. " WHERE items.name =". $item );
echo "<tr>
<td>".$row['name']."</td>
<td align=\"right\">".$row['cost']."</td>
<td align=\"right\">".$row['bids']."</td>
<td align=\"right\">".$row['seller_name']."</td>
</tr>";
}//end while
You need to add one more line in between your update statement and display statement.
$new_record = mysql_fetch_array(mysql_query("SELECT * FROM items WHERE items.name =". $item"));
Then use your echo statement as :
echo "<tr><td>".$new_record ['name']."</td>
<td align=\"right\">".$new_record['cost']."</td>
<td align=\"right\">".$new_record['bids']."</td>
<td align=\"right\">".$new_record['seller_name']."</td>
</tr>";
You should select rows from the table again, if You want to show them after update. In the code snippet above You actually echos old entries from the table.
Just wrap it in an if block
if(mysql_query("UPDATE items SET bids = " .$bids.", cost=" . $price. " WHERE items.name =". $item )){
echo "<td>".$new_record ['name']."</td>
<td align=\"right\">".$new_record['cost']."</td>
<td align=\"right\">".$new_record['bids']."</td>
<td align=\"right\">".$new_record['seller_name']."</td>
</tr>";
}