Random <br> being generated - php

I have a .php file that generates a table based on a directory's content. But for some reason it also generates <br> tags before the table, the more contents inside the directory the more <br> tags.
Here's the code responsible of this:
<main class="mdl-layout__content" style="background-color: white; background-image: url('https://i.warosu.org/data/tg/img/0357/97/1414469732022.gif'); background-size: auto 100%; background-repeat: no-repeat; background-position: center;">
<center>
<div class="page-content" style="padding: 24px; align-items: center; justify-content: center;">
<?php
echo "<div>\n";
echo "<table class=\"mdl-data-table mdl-js-data-table mdl-shadow--2dp\" style=\"min-width:300px\"\n";
echo " <thead>\n";
echo " <tr>\n";
echo " <th class=\"mdl-data-table__cell--non-numeric\">File</th>\n";
echo " <th>Size</th>\n";
echo " </tr>\n";
echo " </thead>\n";
echo " <tbody>";
if ($path) echo '<tr><td colspan="2" style="text-align:center">..</td></tr><br />';
foreach (glob($root.$path.'/*') as $file) {
$file = realpath($file);
$link = substr($file, strlen($root) + 1);
if (is_dir($file)){
echo '<tr><td style="text-align:center; vertical-align:middle"><i class="material-icons" style="vertical-align:middle">folder</i></td><td style="text-align:center; vertical-align:middle"><span style="vertical-align:middle">'.basename($file).'</span></td></tr><br />';
}
else {
$lastpath = path2url($file);
$size = formatSizeUnits(filesize($file));
echo '<tr><td>'.basename($file).'</td><td>'.$size.'</td></tr><br />';
}
}
?>
</tbody>
</table>
</div>
</center>
<button class="show-modal mdl-button mdl-js-button mdl-button--fab mdl-js-ripple-effect mdl-button--colored" id="cornerbutton">
<i class="material-icons">add</i>
</button>
<dialog class="mdl-dialog">
<div class="mdl-dialog__content">
<form enctype="multipart/form-data" action="upload_file.php" method="POST">
<input type="hidden" name="MAX_FILE_SIZE" value="1000000000000" />
Choose a file to upload: <input name="uploadedfile" type="file" /><br />
</div>
<div class="mdl-dialog__actions mdl-dialog__actions--full-width">
<input type="submit" class="mdl-button" value="UPLOAD" ></button>
<button type="button" class="mdl-button close">ABORT MISSION!!</button>
</div>
</form>
</dialog>
</main>
Help

There are br tag added to end of some lines like
echo '<tr><td>'.basename($file).'</td><td>'.$size.'</td></tr>*<br />*';
Just remove those.

Related

Unable to POST form data when I add name tag to a particular input tag?

I have been struggling to figure out the mystery behind this.
Unable to POST form data when I add name to a particular input field. I been starring at the screen for hours to figure out what went wrong.
My Code goes as,
Form Page:
<form action="upload.php" method="POST">
<div class="customer_records">
<div class="customer_records_sub">
<input type="text" list="o_id" name="o_id[]" class="mb-2 mr-sm-2 o_id_input" placeholder="Order ID"
style="width: auto;padding: 10px 50px;display: inline-block;font-size: 16px;
border: 1px solid lightgray;border-radius:5px;vertical-align: text-bottom;background: none;">
<datalist id="o_id">
<?php
$sql_o_id = "SELECT DISTINCT(o_id) FROM quotes";
$result_o_id = $conn->query($sql_o_id);
if ($result_o_id->num_rows > 0) {
while($row_o_id = $result_o_id->fetch_assoc()) {
$o_id = $row_o_id["o_id"];
?>
<option value="<?= $o_id; ?>">
<?php } } else { } ?>
</datalist>
<div class="asins_visible_input mb-2 mr-sm-2"
style="width: auto;padding: 10px 50px;display: inline-block;font-size: 16px;
border: 1px solid lightgray;border-radius:5px;vertical-align: text-bottom;
background: none;height: 45px;min-width: 300px;" >
</div>
<br/>
<div class="asins_list" style="display:none;height: auto;overflow: auto;width: auto;
border: 1px solid lightgray;padding: 2%;border-radius: 5px;
margin-left: 24%;min-width: 400px;">
<?php
$sql_asin_id = "SELECT * FROM quotespos";
$result_asin_id = $conn->query($sql_asin_id);
if ($result_asin_id->num_rows > 0) {
while($row_asin_id = $result_asin_id->fetch_assoc()) {
$asin_id = $row_asin_id["id"];
$asin_p_id = $row_asin_id["p_id"];
$asin_o_id = $row_asin_id["o_id"];
if($asin_p_id == '' || $asin_p_id == NULL) {
$asin_p_id = '(BLANK)';
} else {
$asin_p_id = $asin_p_id;
}
?>
<div class="asin_id indi_asin_<?= $asin_o_id; ?>" style="display:none;padding-left:10px;">
<input type="checkbox" class="asins_input_checkbox" data-id="<?= $asin_id; ?>" data-pid="<?= $asin_p_id; ?>" style="display:inline-block;width: 20px;height: 20px;" />
<p style="display:inline-block;padding-top: 2px;font-size: 16px;vertical-align: super;"><?= $asin_p_id; ?></p>
<div class="asins_div_percentile"
style="diplay:inline-block;float:right;display:none;">
<i class="fa fa-chevron-right" aria-hidden="true"
style="margin-top: 9px;margin-left: 8px;font-size: 14px;"></i>
<input class="asins_div_percentile_input" name="tada"
style="width: 50px;margin-left: 30px;vertical-align: top;
border: 1px solid gray;font-size: 16px;
border-radius:5px;border:1px solid gray;text-align:center;"
type="text" placeholder="%" />
</div>
<br/>
</div>
<?php $sl++; } } else { } ?>
<input type="hidden" name="asins[]" class="asins_hidden_input" />
</div>
</div>
</div>
<input type="hidden" name="bywhom" value="0" />
<input type="hidden" name="date" value="06/12/201" />
<button type="submit" name="submit" class="btn btn-primary mb-2 expense_form_btn"
style="margin-top: 0.8%;font-size:16px;">Submit</button>
</form>
Upload.php page:
$date = $_POST["date"];
$bywhom = $_POST["bywhom"];
echo $bywhom;
In the above form page, forget the array and all, they all work perfectly fine the moment i remove the name tag from the input tag with class asins_div_percentile_input, But the moment I keep something inside the name tag of that asins_div_percentile_input input, form gets submitted but none of the values gets posted. not even the normal input tag values like date mentioned above.
I don't understand what went wrong. Hope I was clear.
Any help is greatly appreciated.
After thinking a bit, I found a way around. Instead of forcing it to send all the empty fields and then take only the fields which have values, I removed the empty fields from DOM at the time of submission.
$(".form_submit_btn").click(function() {
$(".form_submit_btn").prop("disabled", true);
$('.main_parent').find('.asins_input_checkbox').each(function () {
if($(this).prop("checked")) { } else {
$(this).parent().remove();
}
});
$("#add_expense_form").submit();
});
Works fine. Thanks to all who literally taught me a lot through this query. Appreciate your time.

Why is DataTable only loading 5 out of 22 records in PHP/MySql?

I am certain that I am missing something small here but it had me going for 2 days now.
I am doing a SELECT STATEMENT with criteria, populate a DataTable and view records. My problem is that only 5 records is loaded whilst there are 22 records available. I did echo out each line and 22 is returned, not sure where my problem is and I will appreciate any help please.
I have a suspicion that the problem might be in the next line of code where the User_Role is to be returned, no errors though so I am not sure -
$resultUser = $db->get_row_by_field($User_Role_Data,$part_result->userID,'ID');
Code for Datatable (I played around with all options here, not helping) -
<script id="rendered-js">
$(document).ready(function () {
$("table").DataTable({
dom: "<'dt-head clearfix'lrf>t<'dt-foot clearfix'ip>",
bServerSide: false,
deferRender: false,
pageLength: 3,
autoWidth: false,
fixedHeader: true,
responsive: true,
language: {
search: "_INPUT_",
searchPlaceholder: "Search Item",
lengthMenu: "<select>" +
'<option value="10">10</option>' +
'<option value="25">25</option>' +
'<option value="50">50</option>' +
'<option value="100">100</option>' +
'<option value="-1">All</option>' +
"</select> View Rows Per Page",
oPaginate: {
sNext: "<i class='fa fa-mail-forward'></i>",
sPrevious: "<i class='fa fa-mail-reply'></i>"
}
}
});
});
This is the PHP code that returns the records, as above, return is fine, displaying is only 5 -
<tbody>
<?php
$total = 0;
$dealer_id = $user->dealerID;
$part_results = $db->get_results("SELECT * FROM wp_ims_part_booked WHERE dealerid='".$dealer_id."' AND isInvoiced='0' AND isCancelled='0' ORDER BY date_booked ASC");
if(count($part_results)>0){
foreach($part_results as $part_result){
$result = $db->get_row_by_field($part_result->partTable,$part_result->partID,'ID');
$bookingID = $db->get_row_by_field($part_result->partTable,$part_result->bookingID,'ID');
switch($part_result->user_role) {
case "Franchise Dealer":
$User_Role_Data = "wp_ims_user_dealer";
break;
case "OEM Retailer":
$User_Role_Data = "wp_ims_user_oem";
break;
case "Non-OEM Part Retailer":
$User_Role_Data = "wp_ims_user_non_oem";
break;
case "Insurance Company":
$User_Role_Data = "wp_ims_user_insurance";
break;
case "Panel/Body Repair Shop":
$User_Role_Data = "wp_ims_user_panel";
break;
case "Private Individual":
$User_Role_Data = "wp_ims_user_public";
break;
case "Non-Franchise Workshop":
$User_Role_Data = "wp_ims_user_non_franchise_wshop";
}
$resultUser = $db->get_row_by_field($User_Role_Data,$part_result->userID,'ID');
?>
<tr>
<td style="color: #0d9b84; text-align: center; width: 30px;">
<?php echo "#".$part_result->ID?>
</td>
<td style="color: #0d9b84; text-align: center; width: 80px;">
<?php echo $result->partnumber;?>
</td>
<td style="color: #0d9b84; text-align: center; width: 200px;">
<?php echo $result->partdescription;?>
</td>
<td style="color: #0d9b84; text-align: center; width: 70px;">
<?php echo "R ".number_format(($part_result->value_booked_for), 2);?>
</td>
<td style="color: #0d9b84; text-align: center; width: 220px;">
<?php echo "Client: ".$resultUser->name." ".$resultUser->surname;
echo "<br>";
echo "Contact No: ".$resultUser->contactnumber;
echo "<br>";
echo "City: ".$resultUser->usercity;
echo "<br>";
echo "Province: ".$resultUser->userprovince;
?>
</td>
<td style="color: #0d9b84; text-align: center; width: 100px;">
<?PHP
echo $part_result->date_booked;
?>
</td>
<td style="color: #0d9b84; text-align: center; width: 250px;">
<input type="hidden" name="ID" value="<?php echo $part_result->ID;?>" />
<input type="hidden" name="bookingID" value="<?php echo $bookingID;?>" />
<textarea rows="2" cols="30" class="contact-form-text" style="width: 100%; margin-top: 3px;" placeholder="ENTER YOUR NOTE (Required On Cancel)" required></textarea>
<a href="ims_cancel_client_purchase.php?ID=<?php echo $part_result->ID;?>&bookingID=<?php echo $bookingID;?>" class="btn btn-warning btn-block" style="color: #edf61a;">
Cancel Purchase X
<i class="fa fa-angle-right"></i>
</a>
<a href="ims_invoice_to_client.php?ID=<?php echo $part_result->ID;?>&bookingID=<?php echo $bookingID;?>" class="btn btn-success btn-block" style="color: #4cff00;">
Invoice To Client
<i class="fa fa-angle-right"></i>
</a>
<br />
</td>
</tr>
<?php
}
?>
<?PHP } else { ?>
<tr>
<th style="width:900px; text-align: center; font-weight: 600; font-size: 16px; color: #ff6a00;" class="min-tablet-l">
No Outstanding Orders or Bookings found for your Dealership.
</th>
</tr>
<?php } ?
Further notice (see image), the last record does not show the far right column buttons or textarea box, not sure why.

To redirect the url

in the below code i am searching a data before searching my url will be in coursemaster_site and when i search it will be in coursemaster_site/index1 and when i close the search results the url will be in coursemaster_site /coursemaster_site but i want url to be in coursemaster_site after closing the search results.
controller:coursemaster_site
function index1()
{
$data = array();
$keyword = $this->input->post('keyword');
if($keyword!=""){
$data['results'] = $this->coursemaster_model->search($keyword);
}
$this->load->view('coursemaster_view', $data);
}
view:coursemaster_view
<form action="<?php echo site_url('coursemaster_site/index1');?>" method = "post">
<br/><center>SEARCH:<input type="text" name = "keyword" required/>
<input type="submit" name="submit" id="opn" value = "Search" onClick="hide1('hiddendiv')" class="btn-success btn" /></center>
</form>
<?php
if (isset($_POST['submit'])) { // Here
// Do the search here
if($results){
?> <div id='hideme'>
CLOSE<a href='coursemaster_site' class='close_notification' title='Click to Close'>
<img src="<?php echo base_url('img/close.png'); ?>" width="15" height="15" alt="Close" onClick="hide('hideme')"/>
</a><div style="background:#FFFFFF; width:1000px; height: 540px; position: absolute; left: 20%; top: 35%; margin-left: -100px; margin-top: -120px" id="modal" >
<table class="display2 table table-bordered table-striped" id='results'>
<tr>
<th>course_code</th>
<th>course name</th>
</tr>
<tr><?php
foreach ($results as $row) {
?>
<td><?php echo $row->course_code;?></td>
<td><?php echo $row->course_name;?></td>
</tr>
<?php
}
}else{
echo"<div id='hideme'>
CLOSE<a href='coursemaster_site' class='close_notification' title='Click to Close'>";
echo "<div id='modal' style='background:#FFFFFF; width:1000px; height: 525px; position: absolute; left: 20%; top: 35%; margin-left: -100px; margin-top: -110px'>";
}
echo"no results";
echo'</div>';
echo '</div>'; }
// If closing
?>
</table>
</div></div>
<script>
$('a.modal').bind('click', function(event) {
event.preventDefault();
$('#modal').fadeIn(10);
});
function hide(obj) {
var el = document.getElementById(obj);
el.style.display = 'none';
}
function hide1(obj) {
var el = document.getElementById(obj);
el.style.display = 'none';
}
</script>
Change to:
<div id='hideme'>CLOSE
<a href='/coursemaster_site' class='close_notification' title='Click to Close'>
...
on both places. The leading slash makes the href start from root.
Do the following changes and check if it works or not:
<div id='hideme'>
CLOSE<a href='javascript:void(0);' class='close_notification' title='Click to Close'>";

PHP foreach loop is taking time to load thousands of table data in Google Chrome

On a page I have 8500 Employees shown in table data in the form of <tr> and <td>.
The Name of the Employees shown with a checkbox in front of each name of employee.
When I click on checkboxes the I insert the employees data (Employee Name and Employee Id) session.
Everything is working fine but the problem is when I click on check All checkbox then all the employees checkboxes are selected then there is a button named as "View Selected". On the click of this button I want to all the selected employees. When user click on this button a new child window will be opened with selected employee data in the form table row and data.
I am doing this but using session which I have created on the click of employees checkboxes.
Everything is working on Mozilla Firefox but when I check this of Google Chrome then it is not working and I am getting the browser message KillPages or Wait. The loader image of Chrome is shown but data is not loading.
My new child window page code is this where I am reading the session and running the for-each loop to print the data in the form of table data.
<?php require_once("../../includes/global.php");
$sessionName = rq('sessionName');
$employees = $session->read($sessionName);
?>
<script type="text/javascript" src="<?php echo SITEURL_PAGE; ?
>configuration/js/attendancePolicy.js"></script>
<div style="width: 100%;">
<?php if(strpos($sessionName, 'location') !== false) {?>
<h3 style="padding-left:10px;">View <?php echo LOCATION_DISPLAY_NAME?>s</h3>
<?php } else {?>
<h3 style="padding-left:10px;">View <?php echo
us(substr(str_replace('ot_','',$sessionName), 0, -3))?></h3>
<?php }?>
<?php
$totalEmployees = $session->check($sessionName) ? (int)count($session->read($sessionName)) : 0;
?>
<form id="updateEmployeesForm" name="updateEmployeesForm" method="post" action="saveAttendancePolicy.php">
<input type="hidden" name="hidAction" value="addNewPolicy_step3" />
<input type="hidden" name="sessionName" id="sessionName" value="<?php echo $sessionName?>" />
<?php
$styleTab = '';
$style='';
if($totalEmployees > 30){
$styleTab = 'border-bottom: none;';
$style = 'overflow:auto; height: 230px !important; border-bottom: 4px solid #2C90D3;';
}
//for over time policy only
$functionSuffix = '';
if($sessionName == 'ot_locations_cb' || $sessionName == 'ot_divisions_cb' || $sessionName == 'ot_departments_cb' || $sessionName == 'ot_employees_cb') {
$functionSuffix = 'overTimePolicy';
}
$where = rq('where');
$employeeLoadPage = ($sessionName == 'ot_employees_cb')?'otpolicy_ajax':'';
if(stripos($sessionName, 'employee') > -1) {
$js = "closeClildWindow('', 'employeeDiv', 'yes','".$employeeLoadPage."');";
} else if(stripos($sessionName, 'location') > -1) {
$js = "searchPolicySpecificNew('', 'locations', 'locationDiv', {'session':'yes'},'".$functionSuffix."'); updateChildPolicyNew('".$sessionName."', 'yes','".$functionSuffix."');";
} else if(stripos($sessionName, 'division') > -1) {
$js = "searchPolicySpecificNew('', 'divisions', 'divisionDiv', {'session':'yes'},'".$functionSuffix."'); updateChildDepartmentPolicyNew('".$sessionName."', 'locations_cb', 'yes','".$functionSuffix."');";
} else if(stripos($sessionName, 'department') > -1) {
$js = "searchPolicySpecificNew('', 'departments', 'departmentDiv', {'session':'yes'},'".$functionSuffix."'); updateChildjobTitlePolicy('".$sessionName."', 'divisions_cb', 'locations_cb', '','".$functionSuffix."');";
}
if($where == 'viewEmp') {
if($sessionName == 'ot_employees_cb') {
$js="getSelectedEmployeesNew('OT');";
} else {
$js="getSelectedEmployeesNew();";
}
}
?>
<div class="totalRecord" style="float:right; width:99%;text-align:right; margin-top: 5px;">
<label>Total Record(s) :<?php echo $totalEmployees ?></label>
</div>
<div style="margin: 0 2% 0 2%; width: 96%;" class="div_row">
<table cellpadding="0" border="0" cellspacing="0" width="100%" class="bdrtable" style="border-bottom: 0px;">
<thead>
<tr>
<th align="left" scope="col" colspan="5"> <input type="checkbox" name="viewCheckAllName" id="viewCheckAllName" <?php if($totalEmployees > 0) {?> checked="checked"<?php }?> class="class_parent_pop" onClick="sessionCheckBox('class_parent_pop', '<?php echo $sessionName?>_pop', 'parent', this);" />
Check All </th>
</tr>
</thead>
</table>
</div>
<div style="margin-bottom: 2%; margin-left: 2%; margin-right: 2%; width:96%;<?php echo $style;?>" class="div_row">
<table cellpadding="0" border="0" cellspacing="0" width="100%" class="bdrtable" style="<?php echo $styleTab?>">
<?php if($totalEmployees > 0) { ?>
<tr>
<?php $i=1;
foreach($employees as $key=>$employeeArr) {
?>
<td align="left" width="33%"><?php echo $i; ?> </td>
<?php
if($i%3 == 0 && $i != $totalEmployees) {
echo '</tr><tr>';
}
$i++;
}
if($totalEmployees%3 != 0) {
for ($x=($totalEmployees%3); $x < 3; $x++) {
echo '<td align="left" width="33%"> </td>';
}
}
?>
</tr>
<?php }else{ ?>
<tr>
<td colspan="3" align="center"><?php echo "No Data Found"; ?></td>
</tr>
<?php }?>
</table>
</div>
<div class="clear"></div>
<div class="div_row" style="text-align: right; width: 96%; margin:0 2%;">
<?php if($totalEmployees > 0) {?>
<input type="button" name="updateEmp" id="updateEmp" value="Update" class="submit" onClick="sessionCheckBoxPopupUpdate('<?php echo $sessionName?>_pop', '<?php echo $sessionName?>');<?php echo $js; ?>" />
<?php } ?>
<input type="button" name="cancel" id="cancel" value="Cancel" class="submit" onClick="javascript:window.close();" />
</div>
</form>
It may not be the foreach loop that is slow, 8500 is good number of data to load, you might want to page the results.
Why don't you try the same query using phpmyadmin and see the time taken.

CSS/HTML Inline and center two form buttons of separate forms

I am trying to display two form buttons (each belonging to a separate form) inline and centered (Horizontally).
Here's my code:
<div>
<?php
if(($id && $upperConvLim) || ($id && !$upperConvLim && !$lowerConvLim)){
?>
<span> </span>
<form method="post" action="index.php" class="previous">
<input type="submit" value="Previous" name="submit1" />
<?php echo '<input type = "hidden" value="'.$id.'"name = "id" />'; ?>
<?php echo '<input type = "hidden" value="'.$previous.'"name = "previous" />'; ? >
</form>
<?php
}
if(($id && $lowerConvLim) || ($id && !$upperConvLim && !$lowerConvLim)){
?>
<span> </span>
<form method="post" action="index.php" class="next">
<input type="submit" value="Next" name="submit2" />
<?php echo '<input type = "hidden" value="'.$id.'"name = "id" />'; ?>
<?php echo '<input type = "hidden" value="'.$next.'"name = "next" />'; ?>
</form>
<?php
}
?>
</div>
I tried to inline them using the following in my CSS,
form, form div {
display: inline-block;
}
This works fine but I'm unable to center the two buttons. I would like to know both 1) How to center the two buttons as well as 2) If there is a better way to inline them. Appreciate it.
EDIT: Following Cynthia's suggestion, I changed my php/html code to,
<div class="center-form">
<?php
if(($id && $upperConvLim) || ($id && !$upperConvLim && !$lowerConvLim)){
?>
<span> </span>
<form method="post" action="index.php" class="hform">
<input type="submit" value="Previous" name="submit1" />
<?php echo '<input type = "hidden" value="'.$id.'"name = "id" />'; ?>
<?php echo '<input type = "hidden" value="'.$previous.'"name = "previous" />'; ?>
</form>
<?php
}
if(($id && $lowerConvLim) || ($id && !$upperConvLim && !$lowerConvLim)){
?>
<span> </span>
<form method="post" action="index.php" class="hform">
<input type="submit" value="Next" name="submit2" />
<?php echo '<input type = "hidden" value="'.$id.'"name = "id" />'; ?>
<?php echo '<input type = "hidden" value="'.$next.'"name = "next" />'; ?>
</form>
<?php
}
?>
</div>
And my new CSS:
table {
font-family: Verdana;
font-size: 10pt
}
#table4 {
margin-left: auto;
margin-right: auto;
border:1px solid black;
width :70%;
padding:10px;
background-color:#FAFAD2;
}
#table3 {
margin-left: auto;
margin-right: auto;
border:1px solid black;
width :60%;
padding:10px;
background-color:#FFDAB9;
}
/*
form, form div {
display: inline-block;
text-align: center;
}
*/
.center-form { display:block ; width:165px ; margin:auto }
form.hform { display:inline }
input[type=submit] { padding:4px 0 ; width:80px }
Thanks!
Here you go: http://jsfiddle.net/myQtb/
In a nutshell:
Here is the abbreviated HTML code (I just used barebones forms):
<div class="center-form">
<form class="hform">
<input type="submit" name="submit" value="Submit">
</form>
<form class="hform">
<input type="submit" name="submit" value="Reset">
</form>
</div>​
and here is the CSS:
.center-form { display:block ; width:165px ; margin:auto }
form.hform { display:inline }
input[type=submit] { padding:4px 0 ; width:80px }​
Why it works:
Change your form tag styling from inline-block to simply inline. Then enclose BOTH
forms in the .center-form DIV that is as wide as the combined width of both buttons.
Assign display:block to the .center-form DIV and add margin:auto (so that the left / right
margins will auto adjust).
And voila!
This will centre all all elements within a div or form.
form, form div {
text-align: center;
}

Categories