I have this PDO that fetch rows into html table:
<?php
$selectAll = "SELECT * FROM sales WHERE date_now = :date";
$stmtAll=$conn->prepare($selectAll);
$stmtAll->bindValue(':date', date("y-m-d"));
$execAll=$stmtAll->execute();
$result=$stmtAll->fetchAll();
?>
<?php foreach($result as $rows){ ?>
<tr>
<td height="30" align="center"><?php $rows['type'] ?></td>
<td align="center"><?php $rows['provider'] ?></td>
<td align="center"><?php $rows['pay'] ?></td>
<td align="center"><?php $rows['facture'] ?></td>
<td align="center"><?php $rows['type'] ?></td>
<td align="center"><form action='/architect/pages/delete_row.php' method="post">
<input type="hidden" name="rowid" value="" />
<input type="hidden" name="projid" value="" />
<input class="imgClass_dell" type="submit" onclick="return confirm('هل أنت متأكد؟')" name="delete_workers" value="" />
</form></td>
</tr>
<?php } ?>
</table>
This query should select all rows with current date. I have gotten a table with the correct number of rows but with no data (empty table):
You missed the echo before each values.
You could either use:
<td align="center"><?php echo $rows['provider']; ?></td>
Or if you are using PHP 5.4 or later:
<td align="center"><?= $rows['provider'] ?></td>
You forget to echo/print the values.
Replace
<td height="30" align="center"><?php $rows['type'] ?></td>
<td align="center"><?php $rows['provider'] ?></td>
<td align="center"><?php $rows['pay'] ?></td>
<td align="center"><?php $rows['facture'] ?></td>
<td align="center"><?php $rows['type'] ?></td>
with
<td height="30" align="center"><?=$rows['type'] ?></td>
<td align="center"><?=$rows['provider'] ?></td>
<td align="center"><?=$rows['pay'] ?></td>
<td align="center"><?=$rows['facture'] ?></td>
<td align="center"><?=$rows['type'] ?></td>
Note: Short Tags must b enable for above solution. Or alternatively use can replace<?php $rows with <?php echo $rows
Related
Please help me, how to compare 2 name from different query?
I want to compare subject1 with subject2 if its same words it will printing 'YES' (like the image).
So this is my code, my code just read the last query from subject1.
So how can I compare all query from subject1 with all subject2?
<table class="table table-bordered">
<tr>
<td class="table-bordered">No</td>
<td class="table-bordered">Date</td>
<td class="table-bordered">Subject Name</td>
<td class="table-bordered">Subject No</td>
<td class="table-bordered">Revision No</td>
<td class="table-bordered">Trainer</td>
<td class="table-bordered">Institution</td>
</tr>
<?php
$query = mysql_query("SELECT * FROM training_detail AS s JOIN materi AS t JOIN training_history AS u JOIN employee AS v WHERE v.employee_id = $id1 AND s.nik LIKE v.nik AND u.id_materi LIKE t.id_materi AND s.id_riwayat_training LIKE u.id_riwayat_training ");
$i=1;
while($row1 = mysql_fetch_array($query))
{
$date = $row1['date'];
$subject1 = $row1['subject_name'];
?>
<tr>
<td class="table-bordered"><?php echo $i; ?></td>
<td class="table-bordered"><?php echo date("j/F/Y", strtotime($date)); ?></td>
<td class="table-bordered"><?php echo $subject1; ?></td>
<td class="table-bordered"><?php echo $row1['subject_no']; ?></td>
<td class="table-bordered"><?php echo $row1['revision_no']; ?></td>
<td class="table-bordered"><?php echo $row1['trainer']; ?></td>
<td class="table-bordered"><?php echo $row1['institution']; ?></td>
</tr>
<?php
$i++;
}
?>
</table>
</br>
<table class="table table-bordered">
<tr>
Training yang belum diikuti
<td class="table-bordered">No</td>
<td class="table-bordered"></td>
<td class="table-bordered">subject id</td>
<td class="table-bordered">subject namei</td>
<td class="table-bordered">subject no</td>
</tr>
<?php
$query = mysql_query("SELECT * FROM job_name AS r JOIN subject AS q JOIN employee AS p WHERE q.subject_id LIKE r.header_id AND r.job_id LIKE p.id_jabatan AND p.id_karyawan = $id1 ORDER BY q.id_materi ASC ");
$i=1;
while($row2 = mysql_fetch_array($query))
{
$subject2 = $row2['subject_name'];
if (strcasecmp($subject1, $subject2) == 0)
{
?>
<tr>
<td class="table-bordered"><?php echo $i; ?></td>
<td class="table-bordered"><?php echo "YES" ?></td>
<td class="table-bordered"><?php echo $row2['subject_id'] ?></td>
<td class="table-bordered"><?php echo $subject2; ?></td>
<td class="table-bordered"><?php echo $row2['subject_no']; ?></td>
</tr>
<?php
}
else
{
?>
<tr>
<td class="table-bordered"><?php echo $i; ?></td>
<td class="table-bordered"><?php echo "NO" ?></td>
<td class="table-bordered"><?php echo $row2['subject_id'] ?></td>
<td class="table-bordered"><?php echo $subject2; ?></td>
<td class="table-bordered"><?php echo $row2['subject_no']; ?></td>
</tr>
<?php
}
$i++;
}
?>
</table>
You need to use nested loop I guess. Use second while inside of first one.
BTW look at http://php.net/manual/en/control-structures.alternative-syntax.php, it might make your code seem better.
I hav this sql query:
$sql = "SELECT (SELECT SUM(total_pay) FROM workers) total,workers. * FROM workers WHERE projects_id = ".$id;
And I want to display data into table rows:
$stmt = mysqli_query($con, $sql) or die($sql."<br/><br/>".mysqli_errno($con));
<?php while($rows = mysqli_fetch_array($stmt)){ ?>
<form action="update_del.php" method="post">
<th>Payments</th>
<th>Date</th>
<th>Project</th>
<th width="25%">Delete</th>
<tr>
<?php while($rows = mysqli_fetch_array($stmt)){ ?>
<tr>
<td align="center"><?php echo $rows['total_pay']?></td>
<td align="center"><?php echo $rows['date_of_pay']?></td>
<td align="center"><?php echo $name['project_name'] ?></td>
<td align="center"><!--<input class="imgClass_insert" type="submit" name="submit1" value="" />-->
<input class="imgClass_dell" type="submit" onClick="return confirm('Are you sure you want to delete?')" name="delete_workers" value=""/>
</td>
</tr>
</tr>
<tr>
<td colspan="3">Total <?php echo $name['project_name']?></td>
<td><?php echo $rows['total'] ?></td>
</tr>
<?php } ?>
</table>
The problem is, that the sum of the payment is repeated with every row displayed, so how can I display the sum query just once in the end of the table ? Should put it in a single query specified for the sum only ?
You can either remove the total from your query and use PHP to calculate, or you can just simply store the total and use it outside your while statement. Something like
<?php
$total = 0;
while($rows = mysqli_fetch_array($stmt)){
$total = $rows['total'];
?>
<tr>
<td align="center"><?php echo $rows['total_pay']; ?></td>
<td align="center"><?php echo $rows['date_of_pay']; ?></td>
<td align="center"><?php echo $name['project_name']; ?></td>
<td align="center">
<!--<input class="imgClass_insert" type="submit" name="submit1" value="" />-->
<input class="imgClass_dell" type="submit" onClick="return confirm('Are you sure you want to delete?')" name="delete_workers" value=""/>
</td>
</tr>
<?php } ?>
<tr>
<td colspan="3">Total <?php echo $name['project_name']; ?></td>
<td><?php echo $total; ?></td>
</tr>
</table>
Though since you're traversing all the results anyway it would be best to remove it from the SQL and calculate it.
$sql = "SELECT workers.* FROM workers WHERE projects_id = ".$id;
<?php
$total = 0;
while($rows = mysqli_fetch_array($stmt)){
$total += $rows['total_pay'];
?>
<tr>
<td align="center"><?php echo $rows['total_pay']; ?></td>
<td align="center"><?php echo $rows['date_of_pay']; ?></td>
<td align="center"><?php echo $name['project_name']; ?></td>
<td align="center">
<!--<input class="imgClass_insert" type="submit" name="submit1" value="" />-->
<input class="imgClass_dell" type="submit" onClick="return confirm('Are you sure you want to delete?')" name="delete_workers" value=""/>
</td>
</tr>
<?php } ?>
<tr>
<td colspan="3">Total <?php echo $name['project_name']; ?></td>
<td><?php echo $total; ?></td>
</tr>
If i understand your problem properly, then this might help you to generate sum in the last rows as you require.
"SELECT total_pay, date_of_pay,project_name
FROM workers WHERE project_id=".$id."
UNION
SELECT 'ALL', SUM(total_pay)
FROM workers";
I have a database with 3 tables and 6 to 20 rows in each, but my PHP code creates 8 tables when there should be only 2 (2 post in the DB)
But why does it do that, I took the code from a different PHP page, where it works fine?
<?php
session_start();
require_once("connect.php");
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org /TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>Brand check</title>
</head>
<body>
<br />
<br />
<?php
$query = mysql_query("SELECT * FROM under_etage, sal_1, sal_2") or die(mysql_error());
while($row = mysql_fetch_array($query)) {
?>
<table width="1100" border="0" align="center" cellpadding="0" cellspacing="0"lass="bold_font">
<tr>
<td width="150" height="25" class="info"> <?php echo $row["etDate"]; ?></td>
<td width="100" height="25" class="info"> Lys</td>
<td width="100" height="25" class="info"> Skilt</td>
<td width="100" class="info" > Brandtæppe</td>
<td width="100" class="info"> Brand sprøjte</td>
<td width="500" class="info"> Døre</td>
</tr>
<tr>
<td height="20" class="split">Underetage</td>
<td width="50" class="split"> </td>
<td class="split"> </td>
<td class="split"> </td>
<td class="split"> </td>
<td class="split"> </td>
</tr>
<tr>
<td class="sort_bar">Opgang A</td>
<td width="50" height="25" class="info" ><?php echo $row["lys_u_a"]; ?></td>
<td class="info"><?php echo $row["skilt_u_a"]; ?></td>
<td class="info"> </td>
<td class="info"> </td>
<td class="info"><?php echo $row["door_u_a"]; ?></td>
</tr>
<tr>
<td height="25" class="sort_bar">Studie/gang</td>
<td width="50" height="25" class="info"><?php echo $row["lys_u_s"]; ?></td>
<td class="info"><?php echo $row["skilt_u_s"]; ?></td>
<td class="info"> </td>
<td class="info"> </td>
<td class="info"><?php echo $row["door_u_s"]; ?></td>
</tr>
<tr>
<td height="25" class="sort_bar">Opgang B</td>
<td width="50" height="25" class="info"><?php echo $row["lys_u_b"]; ?></td>
<td class="info"><?php echo $row["skilt_u_b"]; ?></td>
<td class="info"> </td>
<td class="info"> </td>
<td class="info"><?php echo $row["door_u_b"]; ?> </td>
</tr>
<tr>
<td height="25" class="sort_bar">Bar - Festrum</td>
<td width="50" height="25" class="info"><?php echo $row["lys_u_bar"]; ?></td>
<td class="info"><?php echo $row["skilt_u_bar"]; ?></td>
<td class="info"> </td>
<td class="info"> </td>
<td class="info"> </td>
</tr>
<tr>
<td height="25" class="sort_bar">Opgang C</td>
<td width="50" height="25" class="info"><?php echo $row["lys_u_c"]; ?></td>
<td class="info"><?php echo $row["skilt_u_c"]; ?></td>
<td class="info"> </td>
<td class="info"> </td>
<td class="info"><?php echo $row["door_u_c"]; ?> </td>
</tr>
<tr>
<td height="25" class="sort_bar">Opgang D</td>
<td width="50" height="25" class="info"><?php echo $row["lys_u_d"]; ?></td>
<td class="info"><?php echo $row["skilt_u_d"]; ?></td>
<td class="info"> </td>
<td class="info"> </td>
<td class="info"><?php echo $row["door_u_d"]; ?> </td>
</tr>
<tr>
<td height="20" class="split">Etager</td>
<td width="50" class="split"> </td>
<td class="split"> </td>
<td class="split"> </td>
<td class="split"> </td>
<td class="split"> </td>
</tr>
<tr>
<td class="grey_bar">1. Sal A</td>
<td width="50" height="25" class="grey_bar" ><?php echo $row["lys_1a"]; ?></td>
<td class="grey_bar"><?php echo $row["skilt_1a"]; ?></td>
<td class="grey_bar"><?php echo $row["bt_1a"]; ?></td>
<td class="grey_bar"><?php echo $row["bs_1a"]; ?></td>
<td class="grey_bar"><?php echo $row["doors_1a"]; ?></td>
</tr>
<tr>
<td class="grey_bar">1. Sal B</td>
<td width="50" height="25" class="grey_bar" ><?php echo $row["lys_1b"]; ?></td>
<td class="grey_bar"><?php echo $row["skilt_1b"]; ?></td>
<td class="grey_bar"><?php echo $row["bt_1b"]; ?></td>
<td class="grey_bar"><?php echo $row["bs_1b"]; ?></td>
<td class="grey_bar"><?php echo $row["doors_1b"]; ?></td>
</tr>
<tr>
<td class="grey_bar">1. Sal C</td>
<td width="50" height="25" class="grey_bar" ><?php echo $row["lys_1c"]; ?></td>
<td class="grey_bar"><?php echo $row["skilt_1c"]; ?></td>
<td class="grey_bar"><?php echo $row["bt_1c"]; ?></td>
<td class="grey_bar"><?php echo $row["bs_1c"]; ?></td>
<td class="grey_bar"><?php echo $row["doors_1c"]; ?></td>
</tr>
<tr>
<td class="grey_bar">1. Sal D</td>
<td width="50" height="25" class="grey_bar" ><?php echo $row["lys_1d"]; ?></td>
<td class="grey_bar"><?php echo $row["skilt_1d"]; ?></td>
<td class="grey_bar"><?php echo $row["bt_1d"]; ?></td>
<td class="grey_bar"><?php echo $row["bs_1d"]; ?></td>
<td class="grey_bar"><?php echo $row["doors_1d"]; ?></td>
</tr>
<tr>
<td height="25" class="sort_bar">2. Sal A</td>
<td width="50" height="25" class="info"><?php echo $row["lys_2a"]; ?></td>
<td class="info"><?php echo $row["skilt_2a"]; ?></td>
<td class="info"><?php echo $row["bt_2a"]; ?></td>
<td class="info"><?php echo $row["bs_2a"]; ?></td>
<td class="info"><?php echo $row["doors_2a"]; ?></td>
</tr>
<tr>
<td height="25" class="sort_bar">2. Sal B</td>
<td width="50" height="25" class="info"><?php echo $row["lys_2b"]; ?></td>
<td class="info"><?php echo $row["skilt_2b"]; ?></td>
<td class="info"><?php echo $row["bt_2b"]; ?></td>
<td class="info"><?php echo $row["bs_2b"]; ?></td>
<td class="info"><?php echo $row["doors_2b"]; ?></td>
</tr>
<tr>
<td height="25" class="sort_bar">2. Sal C</td>
<td width="50" height="25" class="info"><?php echo $row["lys_2c"]; ?></td>
<td class="info"><?php echo $row["skilt_2c"]; ?></td>
<td class="info"><?php echo $row["bt_2c"]; ?></td>
<td class="info"><?php echo $row["bs_2c"]; ?></td>
<td class="info"><?php echo $row["doors_2c"]; ?></td>
</tr>
<tr>
<td height="25" class="sort_bar">2. Sal D</td>
<td width="50" height="25" class="info"><?php echo $row["lys_2d"]; ?></td>
<td class="info"><?php echo $row["skilt_2d"]; ?></td>
<td class="info"><?php echo $row["bt_2d"]; ?></td>
<td class="info"><?php echo $row["bs_2d"]; ?></td>
<td class="info"><?php echo $row["doors_2d"]; ?></td>
</tr>
<tr>
<td class="grey_bar">3. Sal A</td>
<td width="50" height="25" class="grey_bar" ><?php echo $row["lys_3a"]; ?></td>
<td class="grey_bar"><?php echo $row["skilt_3a"]; ?></td>
<td class="grey_bar"><?php echo $row["bt_3a"]; ?></td>
<td class="grey_bar"><?php echo $row["bs_3a"]; ?></td>
<td class="grey_bar"><?php echo $row["doors_3a"]; ?></td>
</tr>
<tr>
<td class="grey_bar">3. Sal B</td>
<td width="50" height="25" class="grey_bar" ><?php echo $row["lys_3b"]; ?></td>
<td class="grey_bar"><?php echo $row["skilt_3b"]; ?></td>
<td class="grey_bar"><?php echo $row["bt_3b"]; ?></td>
<td class="grey_bar"><?php echo $row["bs_3b"]; ?></td>
<td class="grey_bar"><?php echo $row["doors_3b"]; ?></td>
</tr>
<tr>
<td class="grey_bar">3. Sal C</td>
<td width="50" height="25" class="grey_bar" ><?php echo $row["lys_3c"]; ?></td>
<td class="grey_bar"><?php echo $row["skilt_3c"]; ?></td>
<td class="grey_bar"><?php echo $row["bt_3c"]; ?></td>
<td class="grey_bar"><?php echo $row["bs_3c"]; ?></td>
<td class="grey_bar"><?php echo $row["doors_3c"]; ?></td>
</tr>
<tr>
<td class="grey_bar">3. Sal D</td>
<td width="50" height="25" class="grey_bar" ><?php echo $row["lys_3d"]; ?></td>
<td class="grey_bar"><?php echo $row["skilt_3d"]; ?></td>
<td class="grey_bar"><?php echo $row["bt_3d"]; ?></td>
<td class="grey_bar"><?php echo $row["bs_3d"]; ?></td>
<td class="grey_bar"><?php echo $row["doors_3d"]; ?></td>
</tr>
<tr>
<td height="25" class="sort_bar">4. Sal A</td>
<td width="50" height="25" class="info"><?php echo $row["lys_4a"]; ?></td>
<td class="info"><?php echo $row["skilt_4a"]; ?></td>
<td class="info"><?php echo $row["bt_4a"]; ?></td>
<td class="info"><?php echo $row["bs_4a"]; ?></td>
<td class="info"><?php echo $row["doors_4a"]; ?> </td>
</tr>
<tr>
<td height="25" class="sort_bar">4. Sal B</td>
<td width="50" height="25" class="info"><?php echo $row["lys_4b"]; ?></td>
<td class="info"><?php echo $row["skilt_4b"]; ?></td>
<td class="info"><?php echo $row["bt_4b"]; ?></td>
<td class="info"><?php echo $row["bs_4b"]; ?></td>
<td class="info"><?php echo $row["doors_4b"]; ?> </td>
</tr>
<tr>
<td height="25" class="sort_bar">4. Sal C</td>
<td width="50" height="25" class="info"><?php echo $row["lys_4c"]; ?></td>
<td class="info"><?php echo $row["skilt_4c"]; ?></td>
<td class="info"><?php echo $row["bt_4c"]; ?></td>
<td class="info"><?php echo $row["bs_4c"]; ?></td>
<td class="info"><?php echo $row["doors_4c"]; ?> </td>
</tr>
<tr>
<td height="25" class="sort_bar">4. Sal D</td>
<td width="50" height="25" class="info"><?php echo $row["lys_4d"]; ?></td>
<td class="info"><?php echo $row["skilt_4d"]; ?></td>
<td class="info"><?php echo $row["bt_4d"]; ?></td>
<td class="info"><?php echo $row["bs_4d"]; ?></td>
<td class="info"><?php echo $row["doors_4d"]; ?> </td>
</tr>
<tr>
<td class="grey_bar">5. Sal A</td>
<td width="50" height="25" class="grey_bar" ><?php echo $row["lys_5a"]; ?></td>
<td class="grey_bar"><?php echo $row["skilt_5a"]; ?></td>
<td class="grey_bar"><?php echo $row["bt_5a"]; ?></td>
<td class="grey_bar"><?php echo $row["bs_5a"]; ?></td>
<td class="grey_bar"><?php echo $row["doors_5a"]; ?></td>
</tr>
<tr>
<td class="grey_bar">5. Sal B</td>
<td width="50" height="25" class="grey_bar" ><?php echo $row["lys_5b"]; ?></td>
<td class="grey_bar"><?php echo $row["skilt_5b"]; ?></td>
<td class="grey_bar"><?php echo $row["bt_5b"]; ?></td>
<td class="grey_bar"><?php echo $row["bs_5b"]; ?></td>
<td class="grey_bar"><?php echo $row["doors_5b"]; ?></td>
</tr>
<tr>
<td class="grey_bar">5. Sal C</td>
<td width="50" height="25" class="grey_bar" ><?php echo $row["lys_5c"]; ?></td>
<td class="grey_bar"><?php echo $row["skilt_5c"]; ?></td>
<td class="grey_bar"><?php echo $row["bt_5c"]; ?></td>
<td class="grey_bar"><?php echo $row["bs_5c"]; ?></td>
<td class="grey_bar"><?php echo $row["doors_5c"]; ?></td>
</tr>
<tr>
<td class="grey_bar">5. Sal D</td>
<td width="50" height="25" class="grey_bar" ><?php echo $row["lys_5d"]; ?></td>
<td class="grey_bar"><?php echo $row["skilt_5d"]; ?></td>
<td class="grey_bar"><?php echo $row["bt_5d"]; ?></td>
<td class="grey_bar"><?php echo $row["bs_5d"]; ?></td>
<td class="grey_bar"><?php echo $row["doors_5d"]; ?></td>
</tr>
<tr>
<td height="25" class="sort_bar">6. Sal A</td>
<td width="50" height="25" class="info"><?php echo $row["lys_6a"]; ?></td>
<td class="info"><?php echo $row["skilt_6a"]; ?></td>
<td class="info"><?php echo $row["bt_6a"]; ?></td>
<td class="info"><?php echo $row["bs_6a"]; ?></td>
<td class="info"><?php echo $row["doors_6a"]; ?> </td>
</tr>
<tr>
<td height="25" class="sort_bar">6. Sal B</td>
<td width="50" height="25" class="info"><?php echo $row["lys_6b"]; ?></td>
<td class="info"><?php echo $row["skilt_6b"]; ?></td>
<td class="info"><?php echo $row["bt_6b"]; ?></td>
<td class="info"><?php echo $row["bs_6b"]; ?></td>
<td class="info"><?php echo $row["doors_6b"]; ?> </td>
</tr>
<tr>
<td height="25" class="sort_bar">6. Sal C</td>
<td width="50" height="25" class="info"><?php echo $row["lys_6c"]; ?></td>
<td class="info"><?php echo $row["skilt_6c"]; ?></td>
<td class="info"><?php echo $row["bt_6c"]; ?></td>
<td class="info"><?php echo $row["bs_6c"]; ?></td>
<td class="info"><?php echo $row["doors_6c"]; ?> </td>
</tr >
<tr>
<td height="25" class="sort_bar">6. Sal D</td>
<td width="50" height="25" class="info"><?php echo $row["lys_6d"]; ?></td>
<td class="info"><?php echo $row["skilt_6d"]; ?></td>
<td class="info"><?php echo $row["bt_6d"]; ?></td>
<td class="info"><?php echo $row["bs_6d"]; ?></td>
<td class="info"><?php echo $row["doors_6d"]; ?> </td>
</tr>
<tr>
<td height="25" class="grey_bar">7. Sal A</td>
<td width="50" height="25" class="grey_bar"><?php echo $row["lys_7a"]; ?></td>
<td class="grey_bar"><?php echo $row["skilt_7a"]; ?></td>
<td class="grey_bar"><?php echo $row["bt_7a"]; ?></td>
<td class="grey_bar"><?php echo $row["bs_7a"]; ?></td>
<td class="grey_bar"><?php echo $row["doors_7a"]; ?> </td>
</tr>
<tr>
<td height="25" class="grey_bar">7. Sal B</td>
<td width="50" height="25" class="grey_bar"><?php echo $row["lys_7b"]; ?></td>
<td class="grey_bar"><?php echo $row["skilt_7b"]; ?></td>
<td class="grey_bar"><?php echo $row["bt_7b"]; ?></td>
<td class="grey_bar"><?php echo $row["bs_7b"]; ?></td>
<td class="grey_bar"><?php echo $row["doors_7b"]; ?> </td>
</tr>
<tr>
<td height="25" class="grey_bar">7. Sal C</td>
<td width="50" height="25" class="grey_bar"><?php echo $row["lys_7c"]; ?></td>
<td class="grey_bar"><?php echo $row["skilt_7c"]; ?></td>
<td class="grey_bar"><?php echo $row["bt_7c"]; ?></td>
<td class="grey_bar"><?php echo $row["bs_7c"]; ?></td>
<td class="grey_bar"><?php echo $row["doors_7c"]; ?> </td>
</tr>
<tr>
<td height="25" class="grey_bar">7. Sal D</td>
<td width="50" height="25" class="grey_bar"><?php echo $row["lys_7d"]; ?></td>
<td class="grey_bar"><?php echo $row["skilt_7d"]; ?></td>
<td class="grey_bar"><?php echo $row["bt_7d"]; ?></td>
<td class="grey_bar"><?php echo $row["bs_7d"]; ?></td>
<td class="grey_bar"><?php echo $row["doors_7d"]; ?> </td>
</tr>
<tr>
<td height="20" class="split">Taget</td>
<td width="50" class="split"> </td>
<td class="split"> </td>
<td class="split"> </td>
<td class="split"> </td>
<td class="split"> </td>
</tr>
<tr>
<td height="14" class="sort_bar">Taget</td>
<td width="50" height="25" class="info" ><?php echo $row["lys_t"]; ?></td>
<td class="info"><?php echo $row["skilt_t"]; ?></td>
<td class="info"></td>
<td class="info"><?php echo $row["brand_s_t"]; ?></td>
<td class="info"><?php echo $row["door_t"]; ?></td>
</tr>
</table>
<br />
<?php } ?>
</body>
</html>
Follow this example and use your data trust me it will work
// set up your query within a variable to make it easier to work with
$query = "SELECT * FROM people";
$result = mysql_query($query); //this will conect to the database and select the table to run the query on and return the values from that table.
// now we will set up a while loop to retrieve the information from the database table.
while ($person = mysql_fetch_array($result)) {
echo "<h3>". $person['name'] ."</h3>"; // this line will fetch the query result that is stored in the $person variable and find the row ['name'] and display it on screen
echo "<p>". $person['info'] ."</p>";
}
?>
what if you broke the query into sections so the first query selected * from the one table and the next query selected data the other table then pass both variables thru the mysql_fetch_array($query1, $query2)
There's nothing wrong with the result itself.
The image should explain itself.
The table basicly is repeating the whole table for each results instead of displaying the results with multiple lines on one table, its doing 1 line on 1 table many times.
Here's the code that involves it-
<?php
$i=0;
while ($i < $num) {
$f1=mysql_result($result,$i,"id");
$f2=mysql_result($result,$i,"date");
$f3=mysql_result($result,$i,"agentclient");
$f4=mysql_result($result,$i,"propertydescription");
$f5=mysql_result($result,$i,"transactiontype");
$f5=mysql_result($result,$i,"applicabledocument");
$f5=mysql_result($result,$i,"received");
$f5=mysql_result($result,$i,"paid");
?>
<table width="98%" border="0" align="center" cellpadding="3" cellspacing="1" bgcolor="#CCCCCC">
<tr valign="bottom" bgcolor="#000000">
<td width="24"><span class="style1b"><strong>No.</strong></span></td>
<td width="105"><span class="style1b"><strong>Date</strong></span></td>
<td width="57"><span class="style1b"><strong>Agent/client</strong></span></td>
<td width="170"><span class="style1b"><strong>Property/Description</strong></span></td>
<td width="199"><span class="style1b"><strong>Transaction type </strong></span></td>
<td width="235"><span class="style1b"><strong>Applicable document </strong></span></td>
<td width="58"><span class="style1b"><strong>Received</strong></span></td>
<td width="58"><span class="style1b"><strong>Paid</strong></span></td>
</tr>
<tr valign="top" bgcolor="#FFFFFF">
<td><?php echo $f1; ?></td>
<td><?php echo $f2; ?></td>
<td><?php echo $f3; ?></td>
<td><?php echo $f4; ?></td>
<td><?php echo $f5; ?></td>
<td><?php echo $f6; ?></td>
<td><?php echo $f7; ?></td>
<td><?php echo $f8; ?></td>
</tr>
</table>
<?php
$i++;
}
?>
There are lots of way to improve this code, but to fix your immediate problem, just take the header row out of the loop:
<table width="98%" border="0" align="center" cellpadding="3" cellspacing="1" bgcolor="#CCCCCC">
<tr valign="bottom" bgcolor="#000000">
<td width="24"><span class="style1b"><strong>No.</strong></span></td>
<td width="105"><span class="style1b"><strong>Date</strong></span></td>
<td width="57"><span class="style1b"><strong>Agent/client</strong></span></td>
<td width="170"><span class="style1b"><strong>Property/Description</strong></span></td>
<td width="199"><span class="style1b"><strong>Transaction type </strong></span></td>
<td width="235"><span class="style1b"><strong>Applicable document </strong></span></td>
<td width="58"><span class="style1b"><strong>Received</strong></span></td>
<td width="58"><span class="style1b"><strong>Paid</strong></span></td>
</tr>
<?php
$i=0;
while ($i < $num) {
$f1=mysql_result($result,$i,"id");
$f2=mysql_result($result,$i,"date");
$f3=mysql_result($result,$i,"agentclient");
$f4=mysql_result($result,$i,"propertydescription");
$f5=mysql_result($result,$i,"transactiontype");
$f5=mysql_result($result,$i,"applicabledocument");
$f5=mysql_result($result,$i,"received");
$f5=mysql_result($result,$i,"paid");
?>
<tr valign="top" bgcolor="#FFFFFF">
<td><?php echo $f1; ?></td>
<td><?php echo $f2; ?></td>
<td><?php echo $f3; ?></td>
<td><?php echo $f4; ?></td>
<td><?php echo $f5; ?></td>
<td><?php echo $f6; ?></td>
<td><?php echo $f7; ?></td>
<td><?php echo $f8; ?></td>
</tr>
<?php
$i++;
}
?>
</table>
When we run a query in ssms, we can get one or more rows of data per associateID.
However, on a table data,
<table>
<tr>
<td>...</td>
</tr>
</table>
We believe that the solution to our problem is to loop the data and dump contents in a table.
Any ideas how I can accomplish this?
Here is the code I am trying to loop:
<?php
//I need the loop here.
<table>
<tr>
<td class="dataItem" id="SignCode"></td>
<td class="dataItem" id="SignType"></td>
<td class="dataItem" id="SignSize"></td>
<td class="dataItem" id="SignColor"></td>
<td class="dataItem" id="Facing"></td>
<td class="dataItem" id="HorizClear"></td>
<td class="dataItem" id="VertClear"></td>
<td class="dataItem" id="Angle"></td>
<td class="dataItem" id="ReflCoat"></td>
<td class="dataItem" id="Condition"></td>
<td class="dataItem" id="Status"></td>
</tr>
</table>
?>
The data is a combination of query and the Javascript array. The query is
$tsql="select * from mytable where associateId='$aid'";
Then all the form ids are in Javascript like this example:
dojo.byId("SignType").innerHTML = obj["SignType"];
If you show us your php code we can give you a better answer but your code should be somthing like this:
<table>
<?php
// Your loop
while($row = /*fetchData()*/) {
?>
<tr>
<td class="dataItem" id="SignCode"><?php echo $row['SignCode']; ?></td>
<td class="dataItem" id="SignType"><?php echo $row['SignType']; ?></td>
<td class="dataItem" id="SignSize"><?php echo $row['SignSize']; ?></td>
<td class="dataItem" id="SignColor"><?php echo $row['SignColor']; ?></td>
<td class="dataItem" id="Facing"><?php echo $row['Facing']; ?></td>
<td class="dataItem" id="HorizClear"><?php echo $row['HorizClear']; ?></td>
<td class="dataItem" id="VertClear"><?php echo $row['VertClear']; ?></td>
<td class="dataItem" id="Angle"><?php echo $row['Angle']; ?></td>
<td class="dataItem" id="ReflCoat"><?php echo $row['ReflCoat']; ?></td>
<td class="dataItem" id="Condition"><?php echo $row['Condition']; ?></td>
<td class="dataItem" id="Status"><?php echo $row['Status']; ?></td>
</tr>
<?php } ?>
</table>
The code should look something like this:
(It is still unclear how you acquire the data from the DB.)
<?php
$resultSet = ... // <-- somehow aquire a result-set you can loop through
?>
<table>
<?php while ($row = <somehow_get_next_row_from_$resultSet_as_associative_array>) {?>
<tr>
<td class="dataItem" id="SignCode"><?php echo($row["signCode"]); ?></td>
<td class="dataItem" id="SignSize"><?php echo($row["signSize"]); ?></td>
<td class="dataItem" id="SignColor"><?php echo($row["signColor"]); ?></td>
...
<td class="dataItem" id="Status"><?php echo($row["status"]); ?></td>
</tr>
<?php } ?>
</table>
In case the value for id (e.g. "SignCode" etc) is the same as the name of the DB column-name AND the query returns the columns in the order you want the HTML-table columns to be, then the part between <tr> and </tr> could be further simplified as:
...
<tr>
<?php forEach ($row as $key => $value) {?>
<td class="dataItem" id="<?php echo($key); ?>"><?php echo($value); ?></td>
<?php } ?>
</tr>
...