Fill table with php - php

i need to fill a table with mysql data, but i want to add a new line for every 3 mysql records.
filling the table its easy. but how do i tell to add a <tr> to every 3 records??
so far i have this:
<table width="30%" border="0">
<tbody>
<tr>
<?php if($totalRows_rsSdk>0){
do{
?>
<td align="center" valign="middle"><input type="checkbox" class="css-checkbox" name="sdkcheck" id="sdkcheck<?php echo $row_rsSdk['id']; ?>"/><label for="sdkcheck<?php echo $row_rsSdk['id']; ?>" class="css-label2 radGroup3"><?php echo $row_rsSdk['nome']; ?></label></td>
<td align="center" valign="middle"><img src="Images/sdk-icons/<?php echo $row_rsSdk['icon']; ?>" height="70"></td>
<?php } while ($row_rsSdk = mysql_fetch_assoc($rsSdk));} ?>
</tr>
</tbody>
</table>

Try this code:
<table width="30%" border="0">
<tbody>
<tr>
<?php if($totalRows_rsSdk>0){
$counter = 0;
do{
?>
<td align="center" valign="middle"><input type="checkbox" class="css-checkbox" name="sdkcheck" id="sdkcheck<?php echo $row_rsSdk['id']; ?>"/><label for="sdkcheck<?php echo $row_rsSdk['id']; ?>" class="css-label2 radGroup3"><?php echo $row_rsSdk['nome']; ?></label></td>
<td align="center" valign="middle"><img src="Images/sdk-icons/<?php echo $row_rsSdk['icon']; ?>" height="70"></td>
<?php
$blockSize = 3;
$counter++;
if ($counter >= $blockSize) {
$counter = 0;
?>
</tr>
<tr>
<?php
}
} while ($row_rsSdk = mysql_fetch_assoc($rsSdk));} ?>
<?php echo str_repeat('<td></td>',($blockSize-$counter)); ?>
</tr>
</tbody>
</table>

Related

SQL query fails in prod environment on IIS but works in test environment running Apache

I'm having a bit of an issue with quires failing when I upload to the live environment while they are fully functional in the test environment, I'm at a loss at this point about where the error may be so I finally broke down and decided to ask those of stack overflow that may be much more skilled than myself if there's something I've missed. The quires look at serial number information from two different tables to pull system specs and any hard drive information associated with the parent serial
<?php
$Dev_HDD = 0;
$con=mysqli_connect("localhost","username","user_password","database");
// Check connection
if (mysqli_connect_errno())
{
echo "Failed to connect to MySQL: " . mysqli_connect_error();
}
if (isset($_POST["serial"]))
{
$SerialNumber = $_POST["serial"];
$sql ="SELECT system.Manufacturer, system.Model, system.SerialNumber, system.Processor, system.Memory FROM system WHERE SerialNumber = '" .$SerialNumber. "'" ;
if ($result=mysqli_query($con,$sql))
{
// Fetch one and one row
while ($row=mysqli_fetch_row($result))
{
$System_Manufacturer = $row[0];
$System_Model = $row[1];
$System_SerialNumber = $row[2];
$System_Processor = $row[3];
$System_Memory = $row[4];
?>
<table border="0" height="100%" width="100%" align="left" valign="top">
<tr>
<td colspan="2">
<hr />
</td>
</tr>
<tr>
<td colspan="2" valign="top">System Summary:</td>
</tr>
<tr>
<td colspan="2">
<hr />
</td>
</tr>
<tr>
<td>System Manufacturer</td>
<td>
<?php echo $System_Manufacturer; ?>
</td>
</tr>
<tr>
<td>System Model:</td>
<td>
<?php echo $System_Model; ?>
</td>
</tr>
<tr>
<td valign="top">System Serial Number</td>
<td valign="top">
<?php echo $System_SerialNumber; ?>
</td>
</tr>
<tr>
<td valign="top">System Processor</td>
<td valign="top">
<?php echo $System_Processor; ?>
</td>
</tr>
<tr>
<td valign="top">System Memory</td>
<td valign="top">
<?php echo $System_Memory; ?>
</td>
</tr>
<?php
}
// Free result set
mysqli_free_result($result);
}
else
{
echo "The serial number specified could not be located<br>";
}
$sql ="SELECT device.recid, device.Manufacturer, device.Model, device.SerialNumber, device.Capacity, device.RPM, device.ErasureMethod, device.ErasureResults FROM device WHERE SystemSerialNumber = '" . $System_SerialNumber . "'" ;
if ($result=mysqli_query($con,$sql))
{
// Fetch one and one row
while ($row=mysqli_fetch_row($result))
{
$Dev_Recid = $row[0];
$Dev_Manufacturer = $row[1];
$Dev_Model = $row[2];
$Dev_DeviceSerialNumber = $row[3];
$Dev_Capacity = $row[4];
$Dev_RPM = $row[5];
$Dev_ErasureMethod = $row[6];
$Dev_ErasureResults = $row[7];
?>
<tr>
<td colspan="2">
<hr />
</td>
</tr>
<tr>
<td colspan="2" valign="top">Storage Summary(<?php echo $Dev_HDD = $Dev_HDD + 1; ?>):</td>
</tr>
<tr>
<td colspan="2">
<hr />
</td>
</tr>
<tr>
<td>Hard Drive Manufacturer</td>
<td>
<?php echo $Dev_Manufacturer; ?>
</td>
</tr>
<tr>
<td>Hard Drive Model:</td>
<td>
<?php echo $Dev_Model; ?>
</td>
</tr>
<tr>
<td valign="top">Serial Number Lookup</td>
<td valign="top">
<?php echo $Dev_DeviceSerialNumber; ?>
</td>
</tr>
<tr>
<td valign="top">Hard Drive Capacity</td>
<td valign="top">
<?php echo $Dev_Capacity; ?>
</td>
</tr>
<tr>
<td valign="top">Hard Drive Speed</td>
<td valign="top">
<?php echo $Dev_RPM; ?>
</td>
</tr>
<tr>
<td>Erasure Method:</td>
<td>
<?php echo $Dev_ErasureMethod; ?>
</td>
</tr>
<tr>
<td>Erasure Results:</td>
<td>
<?php echo $Dev_ErasureResults; ?>
</td>
</tr>
<tr>
<td>Parent Serial Number:</td>
<td>
<?php echo "<a href='logs/" .$Dev_DeviceSerialNumber.".log' target='_blank'>".$Dev_DeviceSerialNumber."</a> <br>";?>
</td>
</tr>
</table>
<?php
}
}
// Free result set
mysqli_free_result($result);
mysqli_close($con);
}
?>
<?php
echo " <br>";
echo "<pre></pre>";
?>

PHP Nesting do-while loop

Im trying to teach myself php.... I have created a database with 4 elements... region, details, store_name, web_address.
I have created ado-while loop that displays all the records in a 'region'... it displays 'store_name', then 'web_address', then 'details' sorted so all the records with the same 'details' are grouped together;
<table width="600" align="center" border="0" cellspacing="4" >
<tr>
<td colspan="2"><h2>Web Stockists: <strong></strong></h2></td>
<td width="251" colspan="2" align="right"><h3>Region: <?php echo $region_text ?></h3></td>
</tr>
<?php do { ?>
<tr>
<td colspan="2"><strong><?php echo $row_RegionList['store_name']; ?></strong></td>
<td colspan="2" rowspan="2" align="center"> <?php echo '' . $row_RegionList['web_address'] . ''; ?></td>
</tr>
<tr>
<td width="14">
<td width="313"><?php echo $row_RegionList['details']; ?> </tr>
<?php } while ($row_RegionList = mysql_fetch_assoc($RegionList)); ?>
</table>
I now want to make it so every record with the same 'details' value get listed under a 'details' sub heading.
This is my attempt;
<table width="600" align="center" border="0" cellspacing="4" >
<tr>
<td colspan="2"><h2>Web Stockists: <strong></strong></h2></td>
<td width="251" colspan="2" align="right"><h3>Region: <?php echo $region_text ?></h3></td>
</tr>
<?php $details = $row_RegionList['details'];
do { ?>
<tr>
<td width="313"> <h3><?php echo $row_RegionList['details']; ?> </h3></td>
</tr>
<?php do { ?>
<tr>
<td colspan="2"><strong><?php echo $row_RegionList['store_name']; ?></strong></td>
<td colspan="2" rowspan="2" align="center"> <?php echo '' . $row_RegionList['web_address'] . ''; ?></td>
</tr>
<?php } while ($row_RegionList['details'] == $details);
$details = $row_RegionList['details'];
} while ($row_RegionList = mysql_fetch_assoc($RegionList)); ?>
</table>
This makes a heading of 'region' with a sub heading of 'details' but then creates an eternal loop of the first record in the database. can someone show me what I have done wrong?

Table inside nested Table

I am having a nested table with a while loop, I want to add one more nested table in the same row:
Now I want to add one more nested table as each cd contains more than one data like below:
My code is as follows
<?php
if(isset($_POST['viewcd'])){
$queryw = "select * from lib_cd where id=".$_POST['idd'];
$resultw = $mysqli->query($queryw);
?>
<div>
<table border="1">
<thead>
<tr ><th >Select</th>
<th>Well_Number</th>
<th>Well_Name</th>
<th>CD No:</th>
<th >Logs</th>
</tr>
</thead>
<?php
while($rowcd = $resultw->fetch_assoc()){
?>
<tr>
<td><?php echo $rowcd['id'] ?> </td>
<td><?php echo $rowcd['well_no'] ?></td>
<td><?php echo $rowcd['well_name'] ?></td>
<td>
<table border="1" width="100%">
<?php
$querycd = "select * from cd where pidd=".$rowcd['id'];
$resultcd = $mysqli->query($querycd);
while($rowcd = $resultcd->fetch_assoc()){
?>
<tr>
<td ><?php echo $rowcd['cd_no'] ?></td>
/* I want to add one more nested table here*/
</tr>
<?php
}
?>
</table>
</td>
</tr>
<?php
}
}
?>
</table>
</div>
I tried some thing like this,after my second while loop
while($rowcd = $resultcd->fetch_assoc()){
?>
<tr>
<td ><?php echo $rowcd['cd_no'] ?></td>
<td>
<table>
<?php
$queryl = "select * from lib_cd_logs where pid=".$rowcd['cd_no'];
$resultl = $mysqli->query($queryl);
while($rowl = $resultl->fetch_assoc()){
?>
<tr>
<td><?php echo $rowl['logs'] ?></td>
</tr>
<?php
}
?>
</tr>
<?php
}
?>
</table>
</td>
</tr>
<?php
}
}
?>
</table>
</div>
but the result was messed up. I am confused, where I want to end my while loop, I think.
Finally i got as i wish, and i am sharing the code as below
<?php
if(isset($_POST['viewcd'])){
$queryw = "select * from lib_cd where id=".$_POST['idd'];
$resultw = $mysqli->query($queryw);
?>
<div class="container">
<table border="1" align="center" border-collapse="collapse">
<thead>
<tr >
<th >Select</th>
<th>Well_Number</th>
<th>Well_Name</th>
<th width="100">CD No:</th>
<th width="150">Logs</th>
<th width="100">Bottom Depth</th>
<th width="100">Top Depth</th>
<th width="100">Date of Log</th>
</tr>
</thead>
<?php
while($rowcd = $resultw->fetch_assoc()){
?>
<tr>
<td><?php echo $rowcd['id'] ?> </td>
<td align="center"><?php echo $rowcd['well_no'] ?></td>
<td align="center"><?php echo $rowcd['well_name'] ?></td>
<td colspan="5">
<table rules="all">
<tr>
<?php
$querycd = "select * from cd where pidd=".$rowcd['id'];
$resultcd = $mysqli->query($querycd);
while($rowcd = $resultcd->fetch_assoc()){
?>
<td width="100" align="center"><?php echo $rowcd['cd_no'] ?></td>
<td colspan="4">
<table rules="all">
<tr>
<?php
$queryl = "select * from lib_cd_logs where pid=".$rowcd['cd_no'];
$resultl = $mysqli->query($queryl);
while($rowl = $resultl->fetch_assoc()){
?>
<td width="155"><?php echo $rowl['logs'] ?></td>
<td width="105" align="center"><?php echo $rowl['bottom'] ?></td>
<td width="100" align="center"><?php echo $rowl['top'] ?></td>
<td width="100" align="right"><?php echo $rowl['date'] ?></td>
</tr>
<?php
}
?>
</table>
</td>
</tr>
<?php
}
?>
</table>
</td>
<?php
}
}
?>
</tr>
</table>
I hope this is what you meant as per your data table shown above
<div>
<table border="1">
<thead>
<tr ><th >Select</th>
<th>Well_Number</th>
<th>Well_Name</th>
<th>CD No:</th>
<th >Logs</th>
</tr>
</thead>
<tr>
<td>id</td>
<td>well</td>
<td>name</td>
<td>
<table border="1" width="100%">
<tr>
<td>1</td>
</tr>
<tr>
<td>2</td>
</tr>
</table>
</td>
<td>
<table border="1" width="100%">
<tr>
<td>Log1</td>
</tr>
<tr>
<td>Log2</td>
</tr>
</table>
</td>
</tr>
</table>
</div>

Difference between two dates in codeigniter

abscondingsince is a date field with value 2016-08-24 and dateofcontactviaphone is a date field with value 2016-08-26 . when I try to echo timespan($row['absconding since'], $row['dateofcontactviaphone']); its giving 2016-08-2446 Years, 8 Months, 3 Days, 5 Hours, 43 Minutes as the output whereas it should have been 2 days and so on. I have no clue where I am making a mistake. My view code is as below:
<table cellpadding="10px" border="1" style="background:none;width:75%;" RULES="ROWS" class="tab_data">
<thead>
<th>Employee Name</th>
<th>Absconding Since</th>
<th>Absconding Days</th>
<th>Phone Log</th>
<th>Comments on call made</th>
<th>Date of Email Sent</th>
<th>Comments/responses to email recorded</th>
<th>View Absconding Checklist</th>
</thead>
<tbody>
<?php
$serial_no = 1;
$i = 0;
foreach($rows as $row){
$i++;
?>
<tr>
<td style="width:10%">
<?php echo $row['name']; ?>
</td>
</td>
<td style="width:10%">
<?php echo $row['abscondingsince'];
echo timespan($row['abscondingsince'], $row['dateofcontactviaphone']);
?>
</td>
<td style="width:10%">
<?php echo $row['dateofcontactviaphone']; ?>
</td>
<td style="width:10%">
<?php echo $row['commentsphone']; ?>
</td>
<td style="width:10%">
<?php echo $row['dateofcontactviaemail']; ?>
</td>
<td style="width:10%">
<?php echo $row['commentsemail']; ?>
</td>
<td style="width:10%">
<?php
if ($row['last_status'] == 'Accepted'){
echo anchor('exits/view_exit_checklist/'.$row['id'],"<i class='fa fa-eye edit_row' alt='View' title='Edit' rel='".$row['id']."' ></i>",array('rel'=>$row->id,'class'=>'edit_row'));
}
else
{
echo "NA";
}
?>
</td>
</tr>
<?php
} ?>
</tbody>
</table>
Use like this:-
echo timespan(strtotime($row['absconding since']),
strtotime($row['dateofcontactviaphone']));

How to transfer multiple rows output to another php file to process data?

<form name="myForm" action="doControlAcc.php" method="post" onsubmit="return validateForm(this);">
<table cellpadding="0" cellspacing="0" border="20" class="display" id="acc" width="200">
<thead>
<tr><h2>Accessories summary</h2></tr>
<tr>
<th>Type</th>
<th>Currently - Ex Factory</th>
<th>Minimum Required Stock</th>
<th>Update by</th>
<th>Last update</th>
<th>Re-Stock Amount</th>
<th>Stock Out</th>
</tr>
</thead>
<tbody>
<?php
$accessories = array()
$query = "SELECT description, current_stock, min_required_stock, c_ex_factory, last_update from Accessories”;
$result= mysqli_query($link, $query) or die(mysqli_error($link));
$row = mysqli_fetch_array($result);
while($row = mysqli_fetch_array($result)){
$order = $row['c_ex_factory'] - $row['min_required_stock'];
if ($order < 0){
$order = $row['min_required_stock']-$row['c_ex_factory'];
$color = "#FF0000";
}else{
$order = 0;
$color = "#00FF00";
}
?>
<tr>
<td name="accessories[]" id="accessories" value=”<?php echo $row['description'] ?>” <?php echo in_array($row['description', $ accessories) > <?php echo $row['description']; ?> </td>
<td align="center" name="accessories[]" id="accessories" value=”<?php echo $row[''c_ex_factory '] ?>” <?php echo in_array($row[''c_ex_factory ', $ accessories) > <?php echo $row['c_ex_factory']; ?> </td>
<td align="center" name="accessories[]" id="accessories" value=”<?php echo $row[''min_required_stock '] ?>” <?php echo in_array($row[''min_required_stock ', $ accessories) > <?php echo $row['min_required_stock']; ?> </td>
<td align="center" name="accessories[]" id="accessories" value=”<?php echo $row[' name '] ?>” <?php echo in_array($row[' name ', $ accessories) > <?php echo $row['name']; ?> </td>
<td align="center" name="accessories[]"id="accessories" value=”<?php echo $row['description'] ?>” <?php echo in_array($row['description', $ accessories) > <?php echo $row['up_when']; ?> </td>
<td align="center" name="accessories[]" bgcolor="<?php echo $color; ?>" id="accessories" <?php echo in_array($row[' re_stock ', $ accessories) > <input type="text" size="5" name="re_stock" value=" <?php echo $order ?>"/> </td>
<td align="center" name="accessories[]"id="accessories" <?php echo in_array($row[' out_stock ', $ accessories) > <input type="text" size="5" name="out_stock" value ="0"/></td>
</tr>
<?php
}
?>
<tr>
<td> </td>
<td> </td>
<td></td> <td></td> <td></td>
<td><button data-theme="b" id="submit" type="submit">Send order</button></td>
</tr>
</tbody>
</table>
</form>
Hello,
I'm new to web programming.
The code above will fetch the data from database to create a table in PHP, then it will take the user inputs for stock-out and restock and send those to doControlAcc.php file.
The problem I'm facing is I need to create multiple input lines so that users can enter stock-out and re-stock for different products. And I don't know how to pass these multiple lines to doControlAcc.php file after the form is filled. (i.e how can I access accessories array in doControlAcc.php?).
THank you for your help.
This may not be the best way, but you can always use session variables. I can't quite understand the program you are writing, so I can't say whether or not sessions would be safe enough, but if you wanted to use sessions, do something like this:
At the beginning of your file:
<?php
session_start();
?>
And later, when the variable is all set:
$_SESSION['accessories'] = $accessories;
To access it in another code file, you must start the session as shown above in each code file. Then, just do this;
$accessories = $_SESSION['accessories'];

Categories