my php code returns to many tables - php

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)

Related

How to Loop/Parse SOAP response in PHP to get all the results

I am new to PHP and SOAP and trying to get values SOAP response in my PHP code.
With below code I am able to get one set of the response but not all three.
if (count($triphistory->TripHistoryList) > 0) {
$trip_history_data = $triphistory->TripHistoryList[0];
Below is SOAP response and I have to get all the values of 'TripHistoryList'.
<ns2:TripHistoryList>
<ns2:TagSerialNumber>6501099999999</ns2:TagSerialNumber>
<ns2:PlateNumber>ABCD</ns2:PlateNumber>
<ns2:PlateState>VA</ns2:PlateState>
<ns2:TxnTime>2018-07-20T23:22:30.080-04:00</ns2:TxnTime>
<ns2:PlazaId>495010</ns2:PlazaId>
<ns2:Zone>1</ns2:Zone>
<ns2:HovSW>H</ns2:HovSW>
<ns2:HovNom>H</ns2:HovNom>
</ns2:TripHistoryList>
<ns2:TripHistoryList>
<ns2:TagSerialNumber>6501099999999</ns2:TagSerialNumber>
<ns2:PlateNumber>XYZA</ns2:PlateNumber>
<ns2:PlateState>VA</ns2:PlateState>
<ns2:TxnTime>2018-07-20T23:22:30.080-04:00</ns2:TxnTime>
<ns2:PlazaId>951010</ns2:PlazaId>
<ns2:Zone>1</ns2:Zone>
<ns2:HovSW>H</ns2:HovSW>
<ns2:HovNom>H</ns2:HovNom>
</ns2:TripHistoryList>
<ns2:TripHistoryList>
<ns2:TagSerialNumber>6501099999999</ns2:TagSerialNumber>
<ns2:PlateNumber>UGHF</ns2:PlateNumber>
<ns2:PlateState>VA</ns2:PlateState>
<ns2:TxnTime>2018-07-20T23:22:30.080-04:00</ns2:TxnTime>
<ns2:PlazaId>951010</ns2:PlazaId>
<ns2:Zone>1</ns2:Zone>
<ns2:HovSW>T</ns2:HovSW>
<ns2:HovNom>T</ns2:HovNom>
</ns2:TripHistoryList>
Just for Info: I am displaying the output as below. Any Help is appreciated
<tbody>
<tr>
<th width="20%">Tag Serial Number</th>
<th width="20%">Plate_Number</th>
<th width="20%">REAR PLATE JURISDICTION</th>
<th width="20%">TXN TIMESTAMP</th>
<th width="20%">PLAZA ID</th>
<th width="20%">ZONE LANE</th>
<th width="20%">LINK ID</th>
<th width="20%">HOV SW</th>
<th width="20%">HOV NOM Due</th>
</tr>
<tr>
<td width="20%"><?php e($trip_history_data->TagSerialNumber); ?></td>
<td width="20%"><?php e($trip_history_data->PlateNumber); ?></td>
<td width="20%"><?php e($trip_history_data->PlateState); ?></td>
<td width="20%"><?php e($trip_history_data->TxnTime); ?></td>
<td width="20%"><?php e($trip_history_data->PlazaId); ?></td>
<td width="20%"><?php e($trip_history_data->Zone); ?></td>
<td width="20%"><?php e($trip_history_data->PlazaId); ?></td>
<td width="20%"><?php e($trip_history_data->HovSW); ?></td>
<td width="20%"><?php e($trip_history_data->HovNom); ?></td>
</tr>
You can change your code to
<?php
foreach($trip_history_data as $data) {
?>
<tr>
<td width="20%"><?php e($data->TagSerialNumber); ?></td>
<td width="20%"><?php e($data->PlateNumber); ?></td>
<td width="20%"><?php e($data->PlateState); ?></td>
<td width="20%"><?php e($data->TxnTime); ?></td>
<td width="20%"><?php e($data->PlazaId); ?></td>
<td width="20%"><?php e($data->Zone); ?></td>
<td width="20%"><?php e($data->PlazaId); ?></td>
<td width="20%"><?php e($data->HovSW); ?></td>
<td width="20%"><?php e($data->HovNom); ?></td>
</tr>
<?php } ?>

EXIF image in php

I have a page that image gets uploaded to but the image are not the right way.
I know I need to use EXIF but I am new to this and lost where to start on this as it is in a while loop
can any one help me
thx jason
here is my code
<section class ="box_1">
<form id="evaluations" method="post" action="comments_page_add.php" enctype="multipart/form-data">`enter code here`
<table width="100%" border="0" cellpadding="3" cellspacing="1" bgcolor="#CCCCCC">
<tr>
<td bgcolor="#FFFFFF"> </td>
<td colspan="4" bgcolor="#FFFFFF"><strong>Parent Entered</strong> </td>
</tr>
<tr>
<td align="center" bgcolor="#FFFFFF">#</td>
<td align="center" bgcolor="#FFFFFF"><strong>Name</strong></td>
<td align="center" bgcolor="#FFFFFF"><strong>Lastname</strong></td>
</tr>
<?php
while($rows = mysqli_fetch_array($results2)){
?>
<tr>
<td align="center" bgcolor="#FFFFFF"><input name="child[]" type="checkbox" id="child[]" value="<?PHP echo $rows['id']; ?>"></td>
<td bgcolor="#FFFFFF"><?php echo $rows['given_name']; ?></td>
<td bgcolor="#FFFFFF"><?php echo $rows['surname']; ?></td>
</tr>
<?php
}
?>
</table>
</section>
<section class ="box_3">
<?php
while($rows2 = mysqli_fetch_array($results3)){
?>
<table width="100%" border="2" bgcolor="#CCCCCC">
<tr>
<tr><td colspan="4" align="center"><img src='<?php echo $rows2['Photo_parth']; ?>' width='60%' height='150em'></td></tr>
<td align="center" bgcolor="#FFFFFF"><input name="image[]" type="checkbox" id="image[]" value="<?PHP echo $rows2['id']; ?>"></td>
<td bgcolor="#FFFFFF"><?php echo $rows2['id']; ?></td></tr>
<td bgcolor="#FFFFFF"><?php echo $rows2['date']; ?></td>
<td bgcolor="#FFFFFF"><?php echo $rows2['time']; ?></td>
</tr>
</table>
<?php
}
?>
</table>
</section>

empty html table but with correct number of rows

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

How do I shorten my code in php using different condition?

I have problem in using this long sourcecode. Is there any substitute code or condition statement to shorten or minimize the code. I use the if-ElseIf Statement. Thank you!
I actually doing a system regarding on multiple conditions regarding on the specified amount. Ex. If SHARE equal or less than 30,000 their is a specified percentage computed with different months.
<div class="span8" align="center">
<table width="100%">
<tr>
<td align="center" width="50%">
<form action="" method="POST">
<label> *NOTE: Php.36,000.00 - maximum applied loanable amount</label>
<br/>
<label>Share Capital:</label>
<input onBlur="this.value=formatCurrency(this.value)" type="hidden">
<input type="text" name="share" value="0" class="textbox"/><br>
<label>Term:</label>
<select name="terms"/>
<option value="1">1 Month</option>
<option value="2">2 Months</option>
</select> <br />
<input type="submit" name="calculate" class="btn btn-success" value="Let's COMPUTE">
</form></td>
<td width="50%" align="justify" >
<div class="alert alert-info" align="justify" style="font-size:16px">
<?php if(isset($_POST['calculate'])) {
$share = $_POST['share'];
$terms = $_POST['terms'];
?>
<?php if($share <= "30000"){ ?>
<?php if($terms == "1"){
$interest = $share * .0130;
$service_fee = $share * .01;
$filling_fee = 30;
$cash_on_hand = $share - ($service_fee + $interest + $filling_fee);
$loan_receivable = $cash_on_hand + $service_fee + $interest + $filling_fee;
$debit = $loan_receivable;
$credit = $interest + $service_fee + $filling_fee + $cash_on_hand;
?>
<table width="100%">
<tr>
<td width="40%" align="justify"><?php echo "Loan Receivable"; ?></td>
<td width="30%" align="right"><?php echo number_format($loan_receivable, 2); ?> </td>
<td width="30%" align="right"> </td>
</tr>
<tr>
<td width="40%" align="justify"><?php echo "Interest "; ?></td>
<td width="30%" align="right"> </td>
<td width="30%" align="right"><?php echo number_format($interest, 2); ?> </td>
</tr>
<tr>
<td width="40%" align="justify"><?php echo "Service Fee "; ?></td>
<td width="30%" align="right"> </td>
<td width="30%" align="right"><?php echo number_format($service_fee, 2); ?></td>
</tr>
<tr>
<td width="40%" align="justify"><?php echo "Filling Fee "; ?></td>
<td width="30%" align="right"> </td>
<td width="30%" align="right"><?php echo number_format($filling_fee, 2); ?></td>
</tr>
<tr>
<td width="40%" align="justify"><?php echo "Cash On Hand "; ?></td>
<td width="30%" align="right"> </td>
<td width="30%" align="right"><?php echo number_format($cash_on_hand, 2); ?></td>
</tr>
<tr bgcolor="#CCCCCC" style="color:#000000; font-weight:bold">
<td width="40%" align="right"><?php echo "TOTAL "; ?></td>
<td width="30%" align="right"><?php echo number_format($debit, 2); ?></td>
<td width="30%" align="right"><?php echo number_format($credit, 2); ?></td>
</tr>
<tr>
<td><br/><br/></td>
<td><br/><br/></td>
<td><br/><br/></td>
</tr>
<tr>
<td width="40%" align="justify"><?php echo "Applied Loan "; ?></td>
<td width="30%" align="right"><?php echo number_format($share, 2); ?> </td>
</tr>
<tr>
<td width="40%" align="justify"><?php echo "Term: "; ?></td>
<td width="30%" align="right"><?php echo $terms. " month "; ?> </td>
</tr>
</table>
<?php } elseif($terms == "2"){
$interest = $share * .0195;
$service_fee = $share * .01;
$filling_fee = 30;
$cash_on_hand = $share - ($service_fee + $interest + $filling_fee);
$loan_receivable = $cash_on_hand + $service_fee + $interest + $filling_fee;
$debit = $loan_receivable;
$credit = $interest + $service_fee + $filling_fee + $cash_on_hand;
?>
<table width="100%">
<tr>
<td width="40%" align="justify"><?php echo "Loan Receivable"; ?></td>
<td width="30%" align="right"><?php echo number_format($loan_receivable, 2); ?> </td>
<td width="30%" align="right"> </td>
</tr>
<tr>
<td width="40%" align="justify"><?php echo "Interest "; ?></td>
<td width="30%" align="right"> </td>
<td width="30%" align="right"><?php echo number_format($interest, 2); ?> </td>
</tr>
<tr>
<td width="40%" align="justify"><?php echo "Service Fee "; ?></td>
<td width="30%" align="right"> </td>
<td width="30%" align="right"><?php echo number_format($service_fee, 2); ?></td>
</tr>
<tr>
<td width="40%" align="justify"><?php echo "Filling Fee "; ?></td>
<td width="30%" align="right"> </td>
<td width="30%" align="right"><?php echo number_format($filling_fee, 2); ?></td>
</tr>
<tr>
<td width="40%" align="justify"><?php echo "Cash On Hand "; ?></td>
<td width="30%" align="right"> </td>
<td width="30%" align="right"><?php echo number_format($cash_on_hand, 2); ?></td>
</tr>
<tr bgcolor="#CCCCCC" style="color:#000000; font-weight:bold">
<td width="40%" align="right"><?php echo "TOTAL "; ?></td>
<td width="30%" align="right"><?php echo number_format($debit, 2); ?></td>
<td width="30%" align="right"><?php echo number_format($credit, 2); ?></td>
</tr>
<tr>
<td><br/><br/></td>
<td><br/><br/></td>
<td><br/><br/></td>
</tr>
<tr>
<td width="40%" align="justify"><?php echo "Applied Loan "; ?></td>
<td width="30%" align="right"><?php echo number_format($share, 2); ?> </td>
</tr>
<tr>
<td width="40%" align="justify"><?php echo "Term: "; ?></td>
<td width="30%" align="right"><?php echo $terms. " months "; ?> </td>
</tr>
</table>
<!--END OF SHARE 30,000 BELOW --> <?php } ?>
<!--START OF SHARE 30,000 ABOVE --> <?php } elseif($share >= "30001"){ ?>
<?php if($terms == "1"){
$interest = $share * .0130;
$service_fee = $share * .01;
$filling_fee = 30;
$cash_on_hand = $share - ($service_fee + $interest + $filling_fee);
$loan_receivable = $cash_on_hand + $service_fee + $interest + $filling_fee;
$debit = $loan_receivable;
$credit = $interest + $service_fee + $filling_fee + $cash_on_hand;
?>
<table width="100%">
<tr>
<td width="40%" align="justify"><?php echo "Loan Receivable"; ?></td>
<td width="30%" align="right"><?php echo number_format($loan_receivable, 2); ?> </td>
<td width="30%" align="right"> </td>
</tr>
<tr>
<td width="40%" align="justify"><?php echo "Interest "; ?></td>
<td width="30%" align="right"> </td>
<td width="30%" align="right"><?php echo number_format($interest, 2); ?> </td>
</tr>
<tr>
<td width="40%" align="justify"><?php echo "Service Fee "; ?></td>
<td width="30%" align="right"> </td>
<td width="30%" align="right"><?php echo number_format($service_fee, 2); ?></td>
</tr>
<tr>
<td width="40%" align="justify"><?php echo "Filling Fee "; ?></td>
<td width="30%" align="right"> </td>
<td width="30%" align="right"><?php echo number_format($filling_fee, 2); ?></td>
</tr>
<tr>
<td width="40%" align="justify"><?php echo "Cash On Hand "; ?></td>
<td width="30%" align="right"> </td>
<td width="30%" align="right"><?php echo number_format($cash_on_hand, 2); ?></td>
</tr>
<tr bgcolor="#CCCCCC" style="color:#000000; font-weight:bold">
<td width="40%" align="right"><?php echo "TOTAL "; ?></td>
<td width="30%" align="right"><?php echo number_format($debit, 2); ?></td>
<td width="30%" align="right"><?php echo number_format($credit, 2); ?></td>
</tr>
<tr>
<td><br/><br/></td>
<td><br/><br/></td>
<td><br/><br/></td>
</tr>
<tr>
<td width="40%" align="justify"><?php echo "Applied Loan "; ?></td>
<td width="30%" align="right"><?php echo number_format($share, 2); ?> </td>
</tr>
<tr>
<td width="40%" align="justify"><?php echo "Term: "; ?></td>
<td width="30%" align="right"><?php echo $terms. " month "; ?> </td>
</tr>
</table>
<?php } elseif($terms == "2"){
$interest = $share * .0205;
$service_fee = $share * .01;
$filling_fee = 30;
$cash_on_hand = $share - ($service_fee + $interest + $filling_fee);
$loan_receivable = $cash_on_hand + $service_fee + $interest + $filling_fee;
$debit = $loan_receivable;
$credit = $interest + $service_fee + $filling_fee + $cash_on_hand;
?>
<table width="100%">
<tr>
<td width="40%" align="justify"><?php echo "Loan Receivable"; ?></td>
<td width="30%" align="right"><?php echo number_format($loan_receivable, 2); ?> </td>
<td width="30%" align="right"> </td>
</tr>
<tr>
<td width="40%" align="justify"><?php echo "Interest "; ?></td>
<td width="30%" align="right"> </td>
<td width="30%" align="right"><?php echo number_format($interest, 2); ?> </td>
</tr>
<tr>
<td width="40%" align="justify"><?php echo "Service Fee "; ?></td>
<td width="30%" align="right"> </td>
<td width="30%" align="right"><?php echo number_format($service_fee, 2); ?></td>
</tr>
<tr>
<td width="40%" align="justify"><?php echo "Filling Fee "; ?></td>
<td width="30%" align="right"> </td>
<td width="30%" align="right"><?php echo number_format($filling_fee, 2); ?></td>
</tr>
<tr>
<td width="40%" align="justify"><?php echo "Cash On Hand "; ?></td>
<td width="30%" align="right"> </td>
<td width="30%" align="right"><?php echo number_format($cash_on_hand, 2); ?></td>
</tr>
<tr bgcolor="#CCCCCC" style="color:#000000; font-weight:bold">
<td width="40%" align="right"><?php echo "TOTAL "; ?></td>
<td width="30%" align="right"><?php echo number_format($debit, 2); ?></td>
<td width="30%" align="right"><?php echo number_format($credit, 2); ?></td>
</tr>
<tr>
<td><br/><br/></td>
<td><br/><br/></td>
<td><br/><br/></td>
</tr>
<tr>
<td width="40%" align="justify"><?php echo "Applied Loan "; ?></td>
<td width="30%" align="right"><?php echo number_format($share, 2); ?> </td>
</tr>
<tr>
<td width="40%" align="justify"><?php echo "Term: "; ?></td>
<td width="30%" align="right"><?php echo $terms. " months "; ?> </td>
</tr>
</table>
<?php } ?>
<?php } ?>
<?php } ?>
</div> </td>
</tr>
</table>
I think what you could do here is create a function (or have this as part of a set of tools saved in a class) that you can make available for reuse via an include(). To mix the algorithm into your html will severely limit it's possible use elsewhere. It also clutters up your html output when you intersperse it. Creating a function/class->method allows for expandability and porting into other functions/class->methods as well:
<?php
// Create a function that can accept parameters
function CalculateItem($share = 0,$terms = 0)
{
if($share <= 30000)
$multiplier = ($terms == "1")? .0130 : .0195;
elseif($share >= 30001)
$multiplier = ($terms == "1")? .0130 : .0205;
if(empty($multiplier))
return;
$data['share'] = $share;
$data['terms'] = $terms;
$data['interest'] = ($share * $multiplier);
$data['service_fee'] = ($share * .01);
$data['filling_fee'] = 30;
$data['cash_on_hand'] = $share - ($data['service_fee'] + $data['interest'] + $data['filling_fee']);
$data['loan_receivable'] = $data['cash_on_hand'] + $data['service_fee'] + $data['interest'] + $data['filling_fee'];
$data['debit'] = $data['loan_receivable'];
$data['credit'] = $data['interest'] + $data['service_fee'] + $data['filling_fee'] + $data['cash_on_hand'];
return $data;
}
// Get the state of data. Anything but false will trigger the breakout table
$data = (isset($_POST['calculate']))? CalculateItem($_POST['share'],$_POST['terms']) : false;
?>
<div class="span8" align="center">
<table width="100%">
<tr>
<td align="center" width="50%">
<form action="" method="POST">
<label> *NOTE: Php.36,000.00 - maximum applied loanable amount</label>
<br/>
<label>Share Capital:</label>
<input onBlur="this.value=formatCurrency(this.value)" type="hidden">
<input type="text" name="share" value="0" class="textbox"/>
<br>
<label>Term:</label>
<select name="terms"/>
<option value="1">1 Month</option>
<option value="2">2 Months</option>
</select>
<br />
<input type="submit" name="calculate" class="btn btn-success" value="Let's COMPUTE">
</form></td>
<td width="50%" align="justify" >
<div class="alert alert-info" align="justify" style="font-size:16px">
<?php if($data != false) { ?>
<table width="100%">
<tr>
<td width="40%" align="justify"><?php echo "Loan Receivable"; ?></td>
<td width="30%" align="right"><?php echo number_format($data['loan_receivable'], 2); ?></td>
<td width="30%" align="right"></td>
</tr>
<tr>
<td width="40%" align="justify"><?php echo "Interest "; ?></td>
<td width="30%" align="right"></td>
<td width="30%" align="right"><?php echo number_format($data['interest'], 2); ?></td>
</tr>
<tr>
<td width="40%" align="justify"><?php echo "Service Fee "; ?></td>
<td width="30%" align="right"></td>
<td width="30%" align="right"><?php echo number_format($data['service_fee'], 2); ?></td>
</tr>
<tr>
<td width="40%" align="justify"><?php echo "Filling Fee "; ?></td>
<td width="30%" align="right"></td>
<td width="30%" align="right"><?php echo number_format($data['filling_fee'], 2); ?></td>
</tr>
<tr>
<td width="40%" align="justify"><?php echo "Cash On Hand "; ?></td>
<td width="30%" align="right"></td>
<td width="30%" align="right"><?php echo number_format($data['cash_on_hand'], 2); ?></td>
</tr>
<tr bgcolor="#CCCCCC" style="color:#000000; font-weight:bold">
<td width="40%" align="right"><?php echo "TOTAL "; ?></td>
<td width="30%" align="right"><?php echo number_format($data['debit'], 2); ?></td>
<td width="30%" align="right"><?php echo number_format($data['credit'], 2); ?></td>
</tr>
<tr>
<td><br/>
<br/></td>
<td><br/>
<br/></td>
<td><br/>
<br/></td>
</tr>
<tr>
<td width="40%" align="justify"><?php echo "Applied Loan "; ?></td>
<td width="30%" align="right"><?php echo number_format($data['share'], 2); ?></td>
</tr>
<tr>
<td width="40%" align="justify"><?php echo "Term: "; ?></td>
<td width="30%" align="right"><?php echo $data['terms']. " month "; ?></td>
</tr>
</table>
<?php } ?>
</div>
</td>
</tr>
</table>
NOTE:Used previous link and have shortened the code.Please test it properly just did blank coding
<div class="span8" align="center">
<table width="100%">
<tr>
<td align="center" width="50%">
<form action="" method="POST">
<label> *NOTE: Php.36,000.00 - maximum applied loanable amount</label>
<br/>
<label>Share Capital:</label>
<input onBlur="this.value = formatCurrency(this.value)" type="hidden">
<input type="text" name="share" value="0" class="textbox"/><br>
<label>Term:</label>
<select name="terms"/>
<option value="1">1 Month</option>
<option value="2">2 Months</option>
</select> <br />
<input type="submit" name="calculate" class="btn btn-success" value="Let's COMPUTE">
</form></td>
<td width="50%" align="justify" >
<div class="alert alert-info" align="justify" style="font-size:16px">
<?php
if (isset($_POST['calculate'])) {
$share = $_POST['share'];
$terms = $_POST['terms'];
?>
<?php if ($share <= "30000") { ?>
<?php
if ($terms == "1") {
$interest = $share * .0130;
} elseif ($terms == "2") {
$interest = $share * .0195;
if ($terms == "1") {
$interest = $share * .0130;
} elseif ($terms == "2") {
$interest = $share * .0205;
}}
elseif ($share >= 30001) {
if ($terms == "1") {
$interest = $share * .0130;
} elseif ($terms == "2") {
$interest = $share * .0205;
}
}
?>
?>
<table width="100%">
<tr>
<td width="40%" align="justify"><?php echo "Loan Receivable"; ?></td>
<td width="30%" align="right"><?php echo number_format($loan_receivable, 2); ?> </td>
<td width="30%" align="right"> </td>
</tr>
<tr>
<td width="40%" align="justify"><?php echo "Interest "; ?></td>
<td width="30%" align="right"> </td>
<td width="30%" align="right"><?php echo number_format($interest, 2); ?> </td>
</tr>
<tr>
<td width="40%" align="justify"><?php echo "Service Fee "; ?></td>
<td width="30%" align="right"> </td>
<td width="30%" align="right"><?php echo number_format($service_fee, 2); ?></td>
</tr>
<tr>
<td width="40%" align="justify"><?php echo "Filling Fee "; ?></td>
<td width="30%" align="right"> </td>
<td width="30%" align="right"><?php echo number_format($filling_fee, 2); ?></td>
</tr>
<tr>
<td width="40%" align="justify"><?php echo "Cash On Hand "; ?></td>
<td width="30%" align="right"> </td>
<td width="30%" align="right"><?php echo number_format($cash_on_hand, 2); ?></td>
</tr>
<tr bgcolor="#CCCCCC" style="color:#000000; font-weight:bold">
<td width="40%" align="right"><?php echo "TOTAL "; ?></td>
<td width="30%" align="right"><?php echo number_format($debit, 2); ?></td>
<td width="30%" align="right"><?php echo number_format($credit, 2); ?></td>
</tr>
<tr>
<td><br/><br/></td>
<td><br/><br/></td>
<td><br/><br/></td>
</tr>
<tr>
<td width="40%" align="justify"><?php echo "Applied Loan "; ?></td>
<td width="30%" align="right"><?php echo number_format($share, 2); ?> </td>
</tr>
<tr>
<td width="40%" align="justify"><?php echo "Term: "; ?></td>
<td width="30%" align="right"><?php echo $terms . " month "; ?> </td>
</tr>
</table>
<?php } ?>
</div> </td>
</tr>
</table>

Weird table repeating when displaying mysql results

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>

Categories