I want to arrange the table head with my table body, so the data fill have a same type, how can i doing it??
The black square is the correct one
This is my code
<table>
$syntax = 'SELECT customer,type, count(type) as num FROM view_detail GROUP BY type ORDER BY customer';
$rows = $config->prepare($syntax);
$rows->execute();
$result = $rows->fetchAll(PDO::FETCH_OBJ);
?>
</tr>
<td>No</td>
<td>Customer</td>
<?php for($x=0;$x<count($result);$x++){ ?>
<td><?php echo $result[$x]->type; ?></td>
<?php } ?>
<td>Total</td>
<?php $no = 1;
$query = 'SELECT customer,type, count(type) as tipe FROM view_detail GROUP BY customer ORDER BY customer';
$baris = $config->prepare($query);
$baris->execute();
$hasil1 = $baris->fetchAll(PDO::FETCH_OBJ);
for($i=0;$i<count($hasil1);$i++){
$sql = 'SELECT * FROM view_detail WHERE customer = "'.$hasil1[$i]->customer.'" ORDER BY customer';
$row = $config->prepare($sql);
$row->execute();
$hasil = $row->fetchAll(PDO::FETCH_OBJ);
?>
<tr>
<td><?php echo $no; $no++;?></td>
<td><?php echo $hasil[$i]->customer; ?></td>
<?php
for($y=0;$y<count($result);$y++){
if($y < count($hasil)){
?>
<td><?php echo $hasil[$y]->type; ?></td>
<?php }else{ ?>
<td>0</td>
<?php } } }?>
</tr>
</table>
Thanks
I want to make it like this
Edit:
Dynatrade -> MFN200, N50Z, and N70
Super Bloom -> N70, MFN100, MFN120, and MFN150
Related
Im setting up a html table that connected from the database. But I want the table design like the excel which in html table using rowspan. but I cant work out the problem which Im working out.
Please help me to create this format. See the code below
<tbody>
<?php
include_once('connection.php');
$sql = "SELECT * FROM rqn ";
$query = mysqli_query($conn, $sql);
while($row = mysqli_fetch_assoc($query)){
$result = $row['rqn_no'];
?>
<tr>
<td rowspan="2"><?php echo $row['rqn_no'] ?></td>
<td><?php echo $row['date_filed'] ?></td>
<td><?php echo $row['desc_text'] ?></td>
<td><?php echo $row['remarks'] ?></td>
<td><?php echo $row['date_approved'] ?></td>
<td>
<?php
include_once('connection.php');
$sql1 = "SELECT * FROM po_data where po_data.rqn_base = $result ";
$query1 = mysqli_query($conn, $sql1);
while($row1 = mysqli_fetch_assoc($query1)){
?>
<?php echo $row1['po_no'] ?>
<?php
}
?>
</td>
</tr>
<?php
}
?>
</tbody>
Result I Wanted:
https://prnt.sc/md2t2s
Actual Result:https://prnt.sc/md2tpk
You can use rowspan with a div to achieve the result you want. Try this,
<tbody>
<?php
include_once('connection.php');
$sql = "SELECT * FROM rqn ";
$query = mysqli_query($conn, $sql);
while($row = mysqli_fetch_assoc($query)){
$result = $row['rqn_no'];
?>
<tr>
<td rowspan="2"><?php echo $row['rqn_no'] ?></td>
<td><?php echo $row['date_filed'] ?></td>
<td><?php echo $row['desc_text'] ?></td>
<td><?php echo $row['remarks'] ?></td>
<td><?php echo $row['date_approved'] ?></td>
<?php
include_once('connection.php');
$sql1 = "SELECT * FROM po_data where po_data.rqn_base = $result ";
$query1 = mysqli_query($conn, $sql1);
$total_rows = mysqli_num_rows($query1);
// open <td>
echo "<td rowspan=$total_rows>";
while($row1 = mysqli_fetch_assoc($query1)){
?>
<?php echo "<div style='border-bottom:1px solid black'>" . $row1['po_no'] ."</div>" ?>
<?php
}
// close </td>
echo "</td>";
?>
</td>
</tr>
<?php
}
?>
</tbody>
Adjust the CSS according to your need.
Hi this is the final answer to my result.
Output
<tbody>
<?php
include ("connection.php");
$sql = "SELECT * FROM rqn ";
$result= mysqli_query($conn, $sql);
while($row=mysqli_fetch_array($result)):
$ename = $row['rqn_no'];
// count the esal in each ename
$sql2 = "SELECT * FROM po_data WHERE rqn_base=$ename";
$result2 = mysqli_query($conn, $sql2);
$count_result2 = mysqli_num_rows($result2);
?>
<tr >
<td rowspan="<?php echo $count_result2; ?>"><?php echo $row['rqn_no']; ?></td>
<td rowspan="<?php echo $count_result2; ?>"><?php echo $row['date_filed']; ?></td>
<td rowspan="<?php echo $count_result2; ?>"><?php echo $row['desc_text']; ?></td>
<td rowspan="<?php echo $count_result2; ?>"><?php echo $row['remarks']; ?></td>
<td rowspan="<?php echo $count_result2; ?>"><?php echo $row['date_approved']; ?></td>
<?php
// loop each esal
while($row2 = mysqli_fetch_array($result2)):
?>
<td><?php echo $row2['po_no']; ?></td>
</tr>
<?php
endwhile; // endwhile for each esal looping
endwhile; // endwhile for the main looping
?>
</tbody>
Tnx for helping me guys
I have a page that gives me info from database.
Date - notes - account_type
In account_type I have 3 types of account PS: A - B - C.
$Qdaily_entriesD = mysqli_query($connect, "SELECT * FROM daily_entries ORDER BY account_type DESC");
while ($showRowGeneral = mysqli_fetch_assoc($Qdaily_entriesD))
{
?>
<tr>
<td><?php echo $showRowGeneral['account_type'];?></td>
<td><?php echo $showRowGeneral['riyal'];?></td>
<td><?php echo $showRowGeneral['dollars'];?></td>
</tr>
<?php
}
I want when I print the values it came out with different urls for each account_type.
Like: accounts.php?type=A , B or C
This is what i have tried
<?php
$Qdaily_entriesD = mysqli_query($connect, "SELECT * FROM daily_entries ORDER BY account_type DESC");
while ($showRowGeneral = mysqli_fetch_assoc($Qdaily_entriesD))
{
if ($showRowGeneral['account_type'] == 'b')
{
?>
<tr>
<td><?php echo $showRowGeneral['account_type'];?></td>
<td><?php echo $showRowGeneral['riyal'];?></td>
<td><?php echo $showRowGeneral['dollars'];?></td>
</tr>
<?php
}
}
?>
<tr><td colspan='3'><a href='?type=A'>A</a>, <a href='?type=B'>B</a> or <a href='?type=C'>C</a></td></tr>
but how to achieve this?
Thanks advanced.
Have you tried to use $_GET ?
Read this for more info https://www.w3schools.com/php/php_forms.asp
In your code you want to use it like so,
if ($showRowGeneral['account_type'] == $_GET['type'])
If you want to have a link for each line :
$Qdaily_entriesD = mysqli_query($connect, "SELECT * FROM daily_entries ORDER BY account_type DESC");
while ($showRowGeneral = mysqli_fetch_assoc($Qdaily_entriesD))
{
?>
<tr>
<td><?echo $showRowGeneral['account_type'];?></td>
<td><?echo $showRowGeneral['riyal'];?></td>
<td><?echo $showRowGeneral['dollars'];?></td>
<td>your text</td>
</tr>
<?
}
I have this working.
$queryPR = "SELECT * FROM `raport` WHERE DATE(`timestamp`) = CURDATE() AND (lokacioni = 'PR')";
I need the total amount of rows calculated for specific date.
I need also to the SUM('pagesat') somehow but I have no idea how.
Find the whole code below.
I am trying to build something simple to show the income and outcome for 3 locations that we have.
<table class="responsive-table">
<thead>
<tr>
<th>Vetura</th>
<th>Targa</th>
<th>Dite</th>
<th>Pagesa</th>
<th>Cmimi Ditore</th>
<th>Vazhdim</th>
<th>Te Tjera</th>
<th>Shpenzime</th>
<th>Komente</th>
</tr>
</thead>
<tbody>
<?php
$query = "SELECT * FROM `raport` WHERE DATE(`timestamp`) = CURDATE() AND (lokacioni = 'FR')";
$stmt = $DBcon->prepare( $query );
$stmt->execute();
while($row=$stmt->fetch(PDO::FETCH_ASSOC)){
?>
<tr>
<td><?php echo $row['vetura']; ?></td>
<td><?php echo $row['targa']; ?></td>
<td><?php echo $row['dite']; ?></td>
<td><?php echo $row['pagesa']; ?>€</td>
<td><?php echo $row['cmimiditore']; ?>€</td>
<td><?php echo $row['vazhdim']; ?>€</td>
<td><?php echo $row['tetjera']; ?>€</td>
<td><?php echo $row['shpenzime']; ?>€</td>
<td><?php echo $row['koment']; ?></td>
</tr>
<?php
$pagesa = $row['pagesa'];
$tetjera = $row['tetjera'];
$vazhdime = $row['vazhdim'];
$shpenzime = $row['shpenzime'];
}?>
</tbody>
</table>
<?php
$totali = ($pagesa + $vazhdime + $tetjera);
$gtotal = ($totali - $shpenzime);
?>
<div class="card grey">
<hgroup class="totalDitorRaport">
<h2>Total</h2>
<h1><?php echo $gtotal; ?>€</h1>
</hgroup>
</div>
try this
get the sum of the row pagesa in the loop
$queryPR = "SELECT * FROM `raport` WHERE DATE(`timestamp`) = CURDATE() AND (lokacioni = 'PR')";
$stmt = $DBcon->prepare( $query );
$stmt->execute();
$sum = 0;
while($row=$stmt->fetch(PDO::FETCH_ASSOC)){
$sum += $row['pagesa'];
}
echo $sum;
I am using WordPress and the global class $wpdb in order to retrieve data from MySQL database and display the results in a table.
I have 4 dropdown list that allow the user to select the required inputs then based on the selected inputs the system display all the related data for the user selection.
When I try to run the code it display error:
Notice: Array to string conversion
first part of code :
<?php
/*
Template Name: search info
*/
get_header();
?>
<?php
// code for submit button ation
global $wpdb,$_POST;
//variables that handle the retrieved data from mysql database
if(isset($_POST['site_name']))
{
$site_name=$_POST['site_name'];
}
else { $site_name=""; }
if(isset($_POST['owner_name']))
{
$owner_name=$_POST['owner_name'];
}
else { $owner_name=""; }
if(isset($_POST['Company_name']))
{
$company_name=$_POST['Company_name'];
}
else { $company_name=""; }
if(isset($_POST['Subcontractor_name']))
{
$Subcontractor_name=$_POST['Subcontractor_name'];
}
else { $Subcontractor_name="";}
$site_id = ['siteID'];
$equipment_type = ['equipmentTYPE'];
$lat=['latitude'];
$long=['longitude'];
$height = ['height'];
$owner_contact = ['ownerCONTACT'];
$sub_contact = ['subcontractorCONTACT'];
$sub_company = ['subcontractorCOMPANY'];
if(isset($_POST['query_submit']))
{
//query to retrieve all related info of the selected data from the dropdown list
$query_submit =$wpdb->get_results ("select
site_info.siteID,site_info.siteNAME ,site_info.equipmentTYPE,site_coordinates.latitude,site_coordinates.longitude,site_coordinates.height ,owner_info.ownerNAME,owner_info.ownerCONTACT,company_info.companyNAME,subcontractor_info.subcontractorCOMPANY,subcontractor_info.subcontractorNAME,subcontractor_info.subcontractorCONTACT from `site_info`
LEFT JOIN `owner_info`
on site_info.ownerID = owner_info.ownerID
LEFT JOIN `company_info`
on site_info.companyID = company_info.companyID
LEFT JOIN `subcontractor_info`
on site_info.subcontractorID = subcontractor_info.subcontractorID
LEFT JOIN `site_coordinates`
on site_info.siteID=site_coordinates.siteID
where
site_info.siteNAME = `$site_name`
AND
owner_info.ownerNAME = `$owner_name`
AND
company_info.companyNAME = `$company_name`
AND
subcontractor_info.subcontractorNAME = `$Subcontractor_name`
");
?>
<table width="30%" >
<tr>
<td>Site Name</td>
<td>Owner Name</td>
<td>Company Name</td>
<td>Subcontractor Name</td>
</tr>
<tr>
<td><?php echo $site_name ; ?></td>
<td><?php echo $owner_name ; ?></td>
<td><?php echo $company_name ; ?></td>
<td><?php echo $Subcontractor_name ; ?></td>
<td><?php echo $site_id ; ?></td>
<td><?php echo $equipment_type ; ?></td>
<td><?php echo $lat ; ?></td>
<td><?php echo $long ; ?></td>
<td><?php echo $height ; ?></td>
<td><?php echo $owner_contact ; ?></td>
<td><?php echo $sub_contact ; ?></td>
<td><?php echo $sub_company ; ?></td>
</tr>
</table>
<?php } ?>
The second part of code is for retrieve data from database and includes it in the dropdown list.
I will appreciate any help.
You can get rid of the "Array to string conversion" error quite easy.
In these lines, you are creating arrays:
$site_id = ['siteID'];
$equipment_type = ['equipmentTYPE'];
$lat=['latitude'];
...
$sub_company = ['subcontractorCOMPANY'];
...which you later are trying to echo. You simply can't echo arrays.
Just change the above to be strings instead:
$site_id = 'siteID';
$equipment_type = 'equipmentTYPE';
$lat = 'latitude';
...
$sub_company = 'subcontractorCOMPANY';
Note: As others already pointed out, your code is wide open to SQL Injections. You should really escape your data, before using it in any queries.
<table border="1">
<tr>
<th>Firstname</th>
<th>Lastname</th>
<th>Points</th>
</tr>
<?php
global $wpdb;
$result = $wpdb->get_results ( "SELECT * FROM myTable" );
foreach ( $result as $print ) {
?>
<tr>
<td><?php echo $print->firstname;?></td>
</tr>
<?php }
Here's my code sir:
<?php
session_start();
include 'include/db_config.php';
$result = $dbs->prepare("SELECT * FROM service_info ORDER BY id DESC");
/*$result->bindParam(':id', $_SESSION['id']);*/
$result->execute();
for($i=0; $row = $result->fetch(); $i++){
$result2 = $dbs->prepare("SELECT *FROM customer_info ORDER BY id DESC");
$result2->execute();
for($j=0; $row2 = $result2->fetch();$j++){
?>
<tr class="record">
<td><?php echo $row2['firstname'];?></td>
<td><?php echo $row['no_guest']; ?></td>
<td><?php echo $row['type_service']; ?></td>
<td><?php echo $row['datepicker']; ?></td>
<td><?php echo $row['t_time']; ?></td>
<td> delete </td>
</tr>
<?php
}
}
?>
i didnt use a LEFT JOIN for displaying data's from 2 tables. i just want to do it in my own way . But my problem is it duplicates my data . before i inserted my second query its just 2 data's and now its 4 already. i just cant figure it out where is the duplication occurs.
Someone help me out please . Thanks in Advance.
You display data in second for, which is inside first for. So you get result count of customer_info table length*service_info length results. You should save info in arrays and then use only one for cycle. Eg.:
<?php
session_start();
include 'include/db_config.php';
$services = array();
$customers = array();
$result = $dbs->prepare("SELECT * FROM service_info ORDER BY id DESC");
/*$result->bindParam(':id', $_SESSION['id']);*/
$result->execute();
for($i=0; $row = $result->fetch(); $i++){
$services[] = $row;
}
$result2 = $dbs->prepare("SELECT *FROM customer_info ORDER BY id DESC");
$result2->execute();
for($j=0; $row2 = $result2->fetch();$j++){
$customers[] = $row2;
}
foreach($services as $key => $service) {
?>
<tr class="record">
<td><?php echo $customers[$key]['firstname'];?></td>
<td><?php echo $service['no_guest']; ?></td>
<td><?php echo $service['type_service']; ?></td>
<td><?php echo $service['datepicker']; ?></td>
<td><?php echo $service['t_time']; ?></td>
<td> delete </td>
</tr>
<?php
}
?>
Btw, i suggest you use different approach, like joins