If Condition inside php variable - php

I am stuck with a problem.
I have HTML element inside PHP variable. Now i want if condition inside html elements.
My code is like this.
<?php
$x = 1;
$html =
'<style>
b
{
paading:0;
margin:0;
}
</style>
<table width="790px" style="font-family:Open Sans;">
<!--Want If Condition Here-->
if($x != 1)
{
<tr>
<td colspan="2">
My Separate Portion
</td>
</tr>
}
<strong></strong>
<tr> <td colspan="2"> <hr style="background-color:#E44510; height:10px;"> </td> </tr>';
echo $html;
?>
If anyone can help me out, its very appericiable.

<?php
$x = 1;
$html =
'<style>
b
{
paading:0;
margin:0;
}
</style>
<table width="790px" style="font-family:Open Sans;">';
if($x != 1)
{
$html .= '<tr>
<td colspan="2">
My Separate Portion
</td>
</tr>';
}
$html .= '<strong></strong>
<tr> <td colspan="2"> <hr style="background-color:#E44510; height:10px;"> </td> </tr>';
echo $html;
?>

OR else you can use this in easy way..
<?php
$x = 1;
?>
<style>
b
{
paading:0;
margin:0;
}
</style>
<table width="790px" style="font-family:Open Sans;">
<!--Want If Condition Here-->
<?php
if($x != 1)
{
?>
<tr>
<td colspan="2">
My Separate Portion
</td>
</tr>
<?php
}
?>
<strong></strong>
<tr> <td colspan="2"> <hr style="background-color:#E44510; height:10px;"> </td> </tr>

Related

Inserting multiple rows with PHP

After importing a csv file, I'm trying to import the data with an insert statement, which is sending around 250 rows for one table.
The inserting, and code is working very well, but I had to print the insert query and the insert just worked till the row number 100.
PHP screen, which I import csv file data to the screen:
if(#$_FILES[file][type] == 'text/csv' || #$_FILES[file][type] == 'text/comma-separated-values' || #$_FILES[file][type] == 'application/vnd.ms-excel'){
if($_POST['FUNCAO'] == 'FORM_IMPORT')
{
error_reporting(E_ALL);
##### UPLOAD FILE
$uploaddir = 'gap_files/';
#$filename="gap_files/".$_FILES[file][name];
#$uploadfile = $filename;
$count = 0;
$id_linha = 0;
$itens_po = '';
$pos_to_import = '';
if (!#move_uploaded_file($_FILES['file']['tmp_name'], $uploadfile))
{
print "<pre>";
print_r($_FILES);
print "$php_errormsg</pre>";
}
if(#$_FILES[file][name])
{
print '
<html>
<head>
<title>PO</title>
<link rel="stylesheet" type="text/css" href="../_includes/css/padrao.css" >
<script language="JavaScript" type="text/javascript" src="../_includes/js/padrao.js"></script>
<script language="JavaScript" type="text/javascript" src="../_includes/js/po.js"></script>
<script language="JavaScript" type="text/javascript" src="../_includes/js/label.js"></script>
</head>
<body>
<div id="div_report" style="background-color:#2B2B2B; position:fixed; top:0px; width:200%; height:200%; display:none; opacity:0.35; filter:alpha(opacity=35);"> </div>
<div id="div_link_color" style="display:none; position:fixed; margin-left: -300px; margin-top: -240px; left:50%; top:50%; width:600px; height:280px; background-color:#525252; text-align:center; z-index: 1000; text-align:center; border-radius: 0.4em; ">
<center>
<table cellpadding="3" cellspacing="0">
<tr>
<td colspan="3" class="REPORT_EDIT_TITLE" colspan="3" align="center" id="title_box_comment"></td>
</tr>
<tr>
<td colspan="3">
<iframe style="width:587px; height:230px; background-color:#EAF0FA; text-align:center; text-align:center; border-radius: 0.4em; overflow:auto; border:none;" id="frame_link_color" name="frame_link_color"></iframe>
</td>
</tr>
<tr>
<td colspan="3" align="center"><input type="button" name="comments" id="pre_production_comm" onclick="close_link_color();" value="Close" class="button" style="width:60px; height:30px;"></td>
</tr>
</table>
</center>
</div>
<div width="100%" id="FRAMESBOTTON">
<table cellpadding="1" cellspacing="0">
<tr>
<td class="botton-apple"><img src="../img/user.png" /> <b>Information</b> </td>
<td class="botton-apple" onclick="seleciona_div_po(3)"><img src="../img/help.png" /> <b>Help</b> </td>
<td class="botton-apple" onclick="seleciona_div_po(9)"><img src="../img/application.png" /> <b>Import Label</b> </td>
</tr>
</table>
<table width="100%" cellpadding="0" cellspacing="0">
<tr>
<td class="titlestyle" colspan="6" align="center"><b>Labels to import</b></td>
</tr>
</table>
</div>
';
$po = '';
$line=1;
$po_show = '';
$itens_po = '';
$factory_ids = '';
$wrong_price = '';
$import_error = 0;
$invoice_port = '';
$invoice_number = '';
$number_of_invoices = 0;
$invoice_gross_weight = '';
$invoice_total_cartons = '';
$total_pairs_invoice = 0;
$total_amount_invoice = 0;
$total_amount_discount_invoice = 0;
$tr_check_po = '';
$filename="gap_files/".#$_FILES[file][name];
$handle = fopen("$filename", "r");
$actual_po = '';
while (($data = fgetcsv($handle, 1000, ",")) !== FALSE)
{
foreach($data as $varname => $value)
{
if($value){
$data[$varname]=mysql_real_escape_string($value);
}
else{
$data[$varname]="NULL";
}
}
$check_if_inserted_invoice = mysql_query("select * from po_label where po_label.po = '".$data[3]."'");
if(mysql_num_rows($check_if_inserted_invoice) == 0){
if($line != 0){
$count++;
$itens_po .= '
<input type="hidden" name="iten_'.$count.'" value="'.$line.';'.$data[3].';'.$data[26].';'.$data[15].';'.$data[4].';'.$data[8].';'.$data[0].';'.$data[23].';'.$data[1].';"/>
<tr style="background-color:#ECEBEB;" onmouseover="ButtonRegSet(this,1)" onmouseout="ButtonRegSet(this)">
<td class="fontrecord" align="center"><input type="hidden" name="carton_number_'.$line.'" value="'.$line.'" readonly>'.$line.'</td>
<td class="fontrecord" align="center"><input type="hidden" name="po_'.$line.'" value="'.$data[3].'" readonly>'.$data[3].'</td>
<td class="fontrecord" align="center"><input type="hidden" name="carton_'.$line.'" value="'.$data[26].'" readonly>'.$data[26].'</td>
<td class="fontrecord" align="center"><input type="hidden" name="EANCode_'.$line.'" value="'.$data[15].'" readonly>'.$data[15].'</td>
<td class="fontrecord" align="center"><input type="hidden" name="size_'.$line.'" value="'.$data[4].'" readonly>'.$data[4].'</td>
<td class="fontrecord" align="center"><input type="hidden" name="pairs_'.$line.'" value="'.$data[8].'" readonly>'.$data[8].'</td>
<td class="fontrecord" align="center"><input type="hidden" name="customer_style_'.$line.'" value="'.$data[0].'" readonly>'.$data[0].'</td>
<td class="fontrecord" align="center"><input type="hidden" name="material_'.$line.'" value="'.$data[23].'" readonly>'.$data[23].'</td>
<td class="fontrecord" align="center"><input type="hidden" name="colors_'.$line.'" value="'.$data[1].'" readonly>'.$data[1].'</td>
</tr>';
}
$line++;
}
}
fclose($handle);
}
$number_of_invoices++;
print '
<form method="post" action="../_registers/po_import_label.php">
<input type="hidden" maxlength="30" name="FUNCAO" value="insert_import_po" readonly>
<input type="hidden" maxlength="30" name="itens_form" value="'.$line.'" readonly>
<center>
</br>
<table class="round_sub_information_title_close" width="90%">
<tr>
<td colspan="8" class="round_sub_information_title_close" style="background-color:#FFFFFF;">
<div id="id_itens_invoices_'.$number_of_invoices.'" style="display:block;">
<center>
<table cellpadding="0" cellspacing="1" style="min-width:99%; width:99.8%;">
<tr class="line_grid">
<td class="fontrecord" align="center">Carton Number</td>
<td class="fontrecord" align="center">PO</td>
<td class="fontrecord" align="center">Carton Code</td>
<td class="fontrecord" align="center">Case Code</td>
<td class="fontrecord" align="center">Size</td>
<td class="fontrecord" align="center">Quantity</td>
<td class="fontrecord" align="center">Style</td>
<td class="fontrecord" align="center">Material</td>
<td class="fontrecord" align="center">Color</td>
</tr>
'.$itens_po.'
</table>
</center>
</div>
</td>
</tr>
<tr>';
print '
<tr><td class="round_sub_information_title_close" style="background-color:#FFFFFF;"><input type="submit" value="Save"/></td></tr>';
print '</tr>
</table>
</center>
</form>';
}
}
File: "../_registers/po_import_label.php"
<?php
session_start();
if(!$_SESSION["uid"]){
die(header("location: ../login.php"));
}
include('../_library/config.php');
include('../_library/opendb.php');
include("../_library/functions.php");
$s = "insert into po_label (carton,
carton_number,
po,
size,
pairs,
colors,
material,
customer_style,
EANCode) values";
for($i=1;$i<$_POST['itens_form'];$i++)
{
$s .="('".$_POST['carton_'.$i]."',
'".$_POST['carton_number_'.$i]."',
'".$_POST['po_'.$i]."',
'".$_POST['size_'.$i]."',
'".$_POST['pairs_'.$i]."',
'".$_POST['colors_'.$i]."',
'".$_POST['material_'.$i]."',
'".$_POST['customer_style_'.$i]."',
'".$_POST['EANCode_'.$i]."'),";
}
$s = rtrim($s,",");
print $s;
return mysql_query($s) ? 'INSERTED.' : 'ERROR: '.mysql_error();
include '../library/closedb.php';
?>
After import to the screen, I call the insert function to send the data to the database, it is when I got the error.
insert into po_label (carton, carton_number, po, size, pairs, colors, material, customer_style, EANCode) values (...),('10355000000098','98','0355CC0001','7',' 6','CAMEL','SOFT NUBUCK','CC-CRYSTALL','191644000270'),('10355000000099','99','0355CC0001','7',' 6','CAMEL','SOFT NUBUCK','CC-CRYSTALL','191644000270'),('10355000000100','100','0355CC0001','7',' 6','','SOFT NUBUCK','CC-CRYSTALL','191644000270'),('','','','','','','','',''),('','','','','','','','',''),('','','','','','','','',''),('','','','','','','','',''),(...)
Adding an observation: Before I updated the files in my official system, I tried and test it in the Wamp server, where everything works well.
If i have only 100 rows, the insert works well
If i have more than 100 rows, you can check in the bottom that after the row 100 the insert becomes empty
1) Please confirm whether all values coming without spaces by following function
print_r()
2) Use the trim() function to every single data passed in insert query
INSERT INTO TBL_NAME VALUES(
'".trim($value[0])."',
'".trim($value[1]))";
May it will help
I think you should improve your below code with given
// Your code
for($i=1;$i<$_POST['itens_form'];$i++)
{
$s .="('".$_POST['carton_'.$i]."',
'".$_POST['carton_number_'.$i]."',
'".$_POST['po_'.$i]."',
'".$_POST['size_'.$i]."',
'".$_POST['pairs_'.$i]."',
'".$_POST['colors_'.$i]."',
'".$_POST['material_'.$i]."',
'".$_POST['customer_style_'.$i]."',
'".$_POST['EANCode_'.$i]."'),";
}
for($i=1;$i<$_POST['itens_form'];$i++)
{
// Remove POST for columns in which you have allowed null in data table
if($_POST['carton_'.$i] != '' && $_POST['carton_number_'.$i] != '' && $_POST['po_'.$i] != '' && $_POST['size_'.$i] != '' && $_POST['pairs_'.$i] != '' && $_POST['colors_'.$i] != '' && $_POST['material_'.$i] != '' && $_POST['customer_style_'.$i] != '' && $_POST['EANCode_'.$i] != '')
{
$s .="('".$_POST['carton_'.$i]."',
'".$_POST['carton_number_'.$i]."',
'".$_POST['po_'.$i]."',
'".$_POST['size_'.$i]."',
'".$_POST['pairs_'.$i]."',
'".$_POST['colors_'.$i]."',
'".$_POST['material_'.$i]."',
'".$_POST['customer_style_'.$i]."',
'".$_POST['EANCode_'.$i]."'),";
}
}
UPDATE
As per the given comment, you should increase the length of URI. Please check below Increase your URI limit in your apache server.
but the best way to insert bulk data is mysqldump please see below answer for more information regarding mysqldump using PHP Answer

PHP Delete Data with checkbox

So im kinda trying to delete row from my mysql database using checkboxes. Here is my code. Would be glad if someone could write me down simple delete code. Tryed many but failed, stuck for hours with this :(
<html>
<head>
<title>Admin, User</title>
</head>
<body>
<?php include 'connect.php';?>
<?php include 'functions.php';?>
<?php include 'title_bar.php';?>
<h3>Sukurti Nauja uzduoti: </h3>
<form method='post'>
<?php
if(isset($_POST['submit2']))
{
$pav = $_POST['pav'];
$uzduotis = $_POST['uzduotis'];
if(empty($pav) or empty($uzduotis)){
echo "<p>Privalomi visi langai!</p>";
}
else {
$sql = ("INSERT INTO uzduotys VALUES ('','$pav','$uzduotis')");
}
if($database->query($sql) == TRUE)
{
header('location:kurtisalinti.php');
}
else {
echo "<p>Klaida!</p>";
}
}
?>
<p>Uzduoties pavadinimas:
<p><input type='text' name='pav' />
<p>Uzduotis:
<p><textarea name='uzduotis'></textarea>
<p><input type='submit' name='submit2' value='Sukurti Uzduoti' />
</form>
</p></p></p></p>
</form>
<h3>Pasalinti pasirinkta uzduoti is uzduociu saraso: </h3>
<?php
$query = mysqli_query($database,"SELECT uzid,pav,uzduotis FROM uzduotys");
$count=mysqli_num_rows($query);
?>
<table width="400" border="0" cellspacing="1" cellpadding="0">
<tr>
<td><form name="form1" method="post" action="">
<table width="400" border="0" cellpadding="3" cellspacing="1" bgcolor="#CCCCCC">
<tr>
<td align="center" bgcolor="#FFFFFF">#</td>
<td align="center" bgcolor="#FFFFFF"><strong>id</strong></td>
<td align="center" bgcolor="#FFFFFF"><strong>Pavadinimas</strong></td>
<td align="center" bgcolor="#FFFFFF"><strong>Aprasymas</strong></td>
</tr>
<?php
while($rows = mysqli_fetch_array($query)){
?>
<tr>
<td align="center" bgcolor="#FFFFFF"><input name="checkbox[]" type="checkbox" value="<?php echo $row['uzid']; ?>"></td>
<td bgcolor="#FFFFFF"><?php echo $rows['uzid']; ?></td>
<td bgcolor="#FFFFFF"><?php echo $rows['pav']; ?></td>
<td bgcolor="#FFFFFF"><?php echo $rows['uzduotis']; ?></td>
</tr>
<?php
}
?>
<tr>
<td colspan="5" align="center" bgcolor="#FFFFFF"><input name="delete" type="submit" id="delete" value="Istrinti Uzduotis"></td>
</tr>
<?php
?>
</table>
</form>
</td>
</tr>
</table>
</body>
</html>
Welcome to StackOverflow! Generally as a rule of thumb asking to write you some code doesn't get you very far, however I know that some people learn better from seeing it implemented and being able to modify off of that.
There is a number of ways you can do this. Using something like jquery and ajax you can post your requests without having to reload the page. Keep in mind what I have below may not fully work for you since taking the time to do this much already without a database or connection should give you an idea of what you're looking to do. Good luck!
CAUTION: PSUEDO CODE (This may not fully work and is not intended for production) The idea is to show you an approach to achieving what you are looking for.
<?php
include('connect.php');
include('functions.php');
include('title_bar.php');
if(isset($_POST['submit-uzduotis']))
{
$pav = $_POST['pav'];
$uzduotis = $_POST['uzduotis'];
if(empty($pav) or empty($uzduotis))
{
$result = "<span>Privalomi visi langai!</span>";
}
else
{
$sql = ("INSERT INTO uzduotys VALUES ('','$pav','$uzduotis')");
}
if($database->query($sql) == true)
{
header('location:kurtisalinti.php');
}
else
{
$result = "<span>Įvyko klaida!</span>";
}
}
if(isset($_POST['remove']))
{
$id = mysql_real_escape_string($_POST['remove']);
mysqli_query($database, "DELETE FROM uzduotys WHERE uzid = $id");
}
function showTableData()
{
$query = mysqli_query($database, "SELECT uzid, pav, uzduotis FROM uzduotys");
$count = mysqli_num_rows($query);
while($row = mysqli_fetch_array($query))
{
echo '<tr id="'. $row['uzid'] .'">
<td>
<input type="checkbox" name="checkbox[]" value="'. $row['uzid'] .'">
</td>
<td>'. $row['uzid'] .'</td>
<td>'. $row['pav'] .'</td>
<td>'. $row['uzduotis'] .'</td>
<td>
<button id="remove-single" data-id="'. $row['uzid'] .'">REMOVE</button>
</td>
</tr>';
}
}
?>
<html>
<head>
<title>Admin, User</title>
<style>
.uzduotis-table {
background-color: #ccc;
border-collapse: collapse;
}
.uzduotis-table thead > td {
background-color: #333;
font-weight: bold;
}
.uzduotis-table td {
padding: 3px;
text-align: center;
background-color: #fff;
}
label {
display:block;
position:relative;
font-weight: bold;
}
</style>
</head>
<body>
<h3>Sukurti Nauja uzduoti: </h3>
<form method='post'>
<?php echo $result; ?>
<div>
<label>Uzduoties pavadinimas:</label>
<input type='text' name='pav' />
</div>
<div>
<label>Uzduoties:</label>
<textarea name='uzduotis'></textarea>
</div>
<div>
<input type='submit' name='submit-uzduoties' value='Sukurti Uzduoti' />
</div>
</form>
<h3>Pasalinti pasirinkta uzduoti is uzduociu saraso: </h3>
<table class="uzduotis-table">
<thead>
<tr>
<td>#</td>
<td>Id</td>
<td>Pavadinimas</td>
<td>Aprasymas</td>
</tr>
</thead>
<tbody>
<?php showTableData(); ?>
<tr>
<td colspan="5">
<button id="remove-selected" data-id="'. $row['uzid'] .'">REMOVE SELECTED</button>
</td>
</tr>
</tbody>
</table>
<script src="https://code.jquery.com/jquery-2.2.3.min.js" integrity="sha256-a23g1Nt4dtEYOj7bR+vTu7+T8VP13humZFBJNIYoEJo=" crossorigin="anonymous"></script>
<script>
$(document).ready(function(){
// Remove Single (Button)
$('body').on('click', '#remove-single', function() {
remove($(this).data('id'));
});
// Remove All Checked
$('body').on('click', '#remove-selected', function() {
$('.uzduotis-table tr').filter(':has(:checkbox:checked)').each(function() {
remove(this.id);
});
});
function remove(id)
{
console.log("Remove: " + id);
alert('Removing: ' + id);
$.ajax({
type: "POST",
url: '<?php echo $url; ?>',
data: { remove: id },
success: function (data) {
$('#' + id).remove();
}
});
}
})
</script>
</body>
</html>
I cleaned up a bit of the html and styles, just made it easier for me to read. Also I would recommend looking into a library such as PDO to handle your database queries as there currently isn't much in place to protect or safe guard against sql injection.

Pulling last years data from a table

Hello I'm trying to update this scholarship application box. However when the year changed to 2013 it only displays scholarship applicant info from 2013. I'd like it to display info from 2012. I tried messing around with the date but I cant seem to figure it out. Any help would be greatly appreciated!
<?php
$appYear = date("Y").'-'.(date("Y")+1);
$sql = 'select * from sApplication where studentID = "'.$database->iPrep($_SESSION['ID']).'" AND appYear = "'.$appYear.'" LIMIT 1';
$appID = Scholarship::iFindSQL($sql);
$total = count($appID);
if ($total > 0)
{
$app = array_shift($appID);
}
else
{
$app = 0;
}
?>
<li id="item-2">
<div id="appStatus">
<h3>Application Status</h3>
<blockquote>
<?php if ($app->submitted == ('0000-00-00') || !isset($app->submitted)) { ?>
<table style="border:1px solid #000;" width="100%" border="0" cellspacing="5" cellpadding="0">
<tr>
<td width="50%"><strong>Scholarship<br /> 2013-2014</strong></td>
<td width="50" align="right"> <a style="font-size:16px;" href="welcome.php? app=Scholar">Apply Now</a></td>
</tr>
<tr>
<td><strong>Date Submitted</strong></td>
<td align="right"> </td>
</tr>
<tr>
<td><strong>References</strong></td>
<td align="right"> </td>
</tr>
<tr>
<td><strong>Decision</strong></td>
<td> </td>
</tr>
<tr>
<td colspan="2"><hr /></td>
</tr>
<tr>
<td><strong>Scholarship 2012-2013</strong></td>
<td> </td>
</tr>
<tr>
<td><strong>Decision</strong></td>
<td> </td>
</tr>
</table>
<?php } else { ?>
<table style="border:1px solid #000;" width="100%" border="0" cellspacing="5" cellpadding="0">
<tr>
<td width="90%"><strong>Scholarship 2013-2014</strong></td>
<td width="10%" align="right"> </td>
</tr>
<tr>
<td><strong>Date Submitted</strong></td>
<td align="right"><?=dbOutDate($app->submitted)?></td>
</tr>
<tr>
<td><strong>References</strong> </td>
<td align="right"></td>
</tr>
<tr>
<td colspan="2">
<?php
$refs = Reference::iFindSQL("Select * from reference where appID = '".$app->ID."'");?>
<table width="100%" border="0" cellspacing="0" cellpadding="0">
<?php foreach($refs as $ref) { ?>
<tr> <td> <small><?php if($ref->rType == 'Academic Reference'){ echo 'Academic/Artistic/Professional'; } else { echo 'Community Service'; } ?></small></td> <td align="right"><?=$ref->status?></td></tr>
<?php } ?>
</table>
</td>
</tr>
<tr>
<td><strong>Decision</strong></td>
<td align="right">
<?php
if ($app->complete == 'Approved') { echo 'Approved'; }
if ($app->complete == 'Declined') { echo 'Declined'; }
if ($app->complete == 'Pending') { echo 'Pending'; }
if ($app->complete == 'Incomplete') { echo 'Incomplete'; }
Remove the WHERE clause that limits the year. Use ORDER BY to sort by year, descending.
$sql = 'select * from sApplication
where studentID = "'.$database->iPrep($_SESSION['ID']).
'" ORDER BY appYear DESC LIMIT 1';

Displaying Records in Multiple Columns Using PHP

I'm trying to display two (2) columns instead of my current one (1) column.
My example here:
http://freeskateboardsticker.com/news/authors.php
I have rewritten the script many times, but I cannot seem to get the rows and columns to display correctly and still keep the pagination intact.
Below is my script:
<?php include_once(realpath("templates/top.php")); ?>
<?php include_once(realpath("templates/$templates/mid1.php")); ?>
<?php
$page = #$_GET["page"];
$start = #$_GET["start"];
if (!is_numeric($page) || $page < 1)
$page = 1;
if ($page == 1)
$start = 0;
else
$start = ($page * $authorsPerPage) - $authorsPerPage;
$aResult = mysql_query("select pk_alId, alEmail, alFName, alLName, alBio, alDateJoined from tbl_AdminLogins order by alFName, alLName limit $start, $authorsPerPage");
$numRows = mysql_num_rows(mysql_query("select pk_alId from tbl_AdminLogins order by alFName, alLName"));
if ($numRows > 0) {
?>
<!-- Start Authors -->
<div align="center">
<center>
<TABLE WIDTH="86%" BORDER="0" CELLSPACING="0" CELLPADDING="0">
<TR>
<TD WIDTH="100%" HEIGHT="20" COLSPAN="2" ALIGN="right" class="BodyText" VALIGN="top"><FONT COLOR="#0B75AF"> <?PHP
if ($page > 1)
$nav .= "<a href='authors.php?page=" . ($page - 1) . "'><span class='Link1'><u>« Prev</u></span></a> | ";
for ($i = 1; $i <= ceil($numRows / $authorsPerPage); $i++)
if ($i == $page)
$nav .= "<a href='authors.php?page=$i'><span class='Link4'><b>$i</b></span></a> | ";
else
$nav .= "<a href='authors.php?page=$i'><span class='Link1'>$i</span></a> | ";
if (($start + $authorsPerPage) < $numRows && $numRows > 0)
$nav .= "<a href='authors.php?page=" . ($page + 1) . "'><span class='Link1'><u>Next »</u></span></a>";
if (substr(strrev($nav), 0, 2) == " |")
$nav = substr($nav, 0, strlen($nav) - 2);
echo $nav . "<br> ";
?></FONT>
</TD>
</TR>
</TABLE>
<?php while ($aRow = mysql_fetch_array($aResult)) { ?>
<div align="center"><center>
<TABLE WIDTH="720" CELLSPACING="0" CELLPADDING="0" BORDER="0">
<TR>
<TD WIDTH="185"> <?php if ($showAuthorImages) { ?><img src="imageview.php?what=getAuthorPic&authorId=<?php echo $aRow["pk_alId"]; ?>"> <?php } ?></TD>
<TD WIDTH="5" VALIGN="top"> </TD>
<TD WIDTH="530" VALIGN="MIDDLE"><SPAN CLASS="BodyHeading1"><?PHP echo $aRow["alFName"]; ?></SPAN>
<BR><span class="Text1"><?php echo $aRow["alBio"]; ?></span><br></TD>
</TR>
<TR>
<TD COLSPAN="3"> </TD>
</TR>
</TABLE>
</center></div>
<?php } ?>
<div align="center">
<center>
<table width="96%" border="0" cellspacing="0" cellpadding="0">
<tr>
<td width="100%" height="20" colspan="2" align="right" valign="top">
<SPAN CLASS="Text4"><?php echo $nav . "<br> "; ?></SPAN>
<br>
</td>
</tr>
</table>
</center>
</div>
<!-- End Authors -->
<?php
} else {
// No authors found in the database
?>
<!-- StartAuthors -->
<div align="center">
<center>
<table width="96%" border="0" cellspacing="0" cellpadding="0">
<tr>
<td width="100%" colspan="2" bgcolor="#FFFFFF" height="21">
<span class="BodyHeading">
<br>No Authors Found
</span>
<span class="Text1">
<br><br>
No authors were found in the database. Please use
the link below to return to our home page.
<br><br>
</span>
Return Home
</td>
</tr>
</table>
</center>
</div>
<!-- End Authors -->
<?php
}
?>
Do not use font tag, it is deprecated
br /> not br>
If you are writing then write all other tags also in lower case
Use some MySQLi library (PDO etc)
Do not put center and div with align center tag into while cycle
Build table rows in while cycle, not one table per one author (table beginning before while, table ending after while cycle, inside while leave onl tr/td generation)
Move your loop inside the table, to create a new row per iteration, not a new table:
<div align="center">
<center>
<TABLE WIDTH="720" CELLSPACING="0" CELLPADDING="0" BORDER="0">
<?php while ($aRow = mysql_fetch_array($aResult)) { ?>
<TR>
<TD WIDTH="185"> <?php if ($showAuthorImages) { ?><img src="imageview.php?what=getAuthorPic&authorId=<?php echo $aRow["pk_alId"]; ?>"> <?php } ?></TD>
<TD WIDTH="5" VALIGN="top"> </TD>
<TD WIDTH="530" VALIGN="MIDDLE"><SPAN CLASS="BodyHeading1"><?PHP echo $aRow["alFName"]; ?></SPAN>
<BR><span class="Text1"><?php echo $aRow["alBio"]; ?></span><br></TD>
</TR>
<TR>
<TD COLSPAN="3"> </TD>
</TR>
<?php } ?>
</TABLE>
</center>
</div>

Printing website correctly

I am trying to make a website that reads from a csv file and render the data on the screen in a printable format (it is for printing tickets). The page creates 2 tickets per row and loops threw until it runs out of data. It all works perfectly and looks just the way i want it but, when i print it the 3rd row down has one of the rows of text move up onto the line above it. My question is how can i make it print the way it is seen on the screen and why would it screw up only the 3rd row when all rows are made with the same code.
Thanks
EDIT:
while (!feof($file_handle)){`
$csvText = fgetcsv($file_handle, 1024);
$username = $csvText[1];
$password = $csvText[2];
$profile = $csvText[3];
$daysValid = $csvText[4];
$expiry = $csvText[5];
if($pos == 0)
{
if($count == 5){
echo "<p><br /></p>";
$count = 0;
}else{
$count++;
}
echo "<div class='itemRow'>";
echo "<div class='left'>";
$pos = 1;
?>
<h4 class="centre">Internet Access Voucher</h4>
<img class="image" src="./icon.jpg" />
<div class="info">
<table>
<tr>
<td>
Username
</td>
</tr>
<tr>
<td>
Password
</td>
</tr>
<tr>
<td>
Profile
</td>
</tr>
<tr>
<td>
Valid for
</td>
</tr>
<tr>
<td>
Expiry date
</td>
</tr>
</table>
</div>
<div class="uniqueInfo">
<table>
<tr>
<td>
<?php echo $username;?>
</td>
</tr>
<tr>
<td>
<?php echo $password;?>
</td>
</tr>
<tr>
<td>
<?php echo $profile;?>
</td>
</tr>
<tr>
<td>
<?php echo $daysValid;?>
</td>
</tr>
<tr>
<td>
<?php echo $expiry;?>
</td>
</tr>
</table>
</div>
<p class="centre"><br />Please remember to disconnect to stop each session.</p>
</div>
<br />
<?php
} else {
?>
<div class="right">
<h4 class="centre">Internet Access Voucher</h4>
<img class="imageRight" src="./icon.jpg" />
<div class="infoRight">
<table>
<tr>
<td>
Username
</td>
</tr>
<tr>
<td>
Password
</td>
</tr>
<tr>
<td>
Profile
</td>
</tr>
<tr>
<td>
Valid for
</td>
</tr>
<tr>
<td>
Expiry date
</td>
</tr>
</table>
</div>
<div class="uniqueInfoRight">
<table>
<tr>
<td>
<?php echo $username;?>
</td>
</tr>
<tr>
<td>
<?php echo $password;?>
</td>
</tr>
<tr>
<td>
<?php echo $profile;?>
</td>
</tr>
<tr>
<td>
<?php echo $daysValid;?>
</td>
</tr>
<tr>
<td>
<?php echo $expiry;?>
</td>
</tr>
</table>
</div>
<p class="centre"><br />Please remember to disconnect to stop each session.</p>
</div>
</div>
<?php
$pos = 0;
}
}
?>
CSS
.centre
{
text-align:center;
}
.itemRow
{
position:relative;
top:0px;
}
.left
{
width:500px;
position:relative;
font-family:Comic Sans, Comic sans MS, cursive;
/*border-style:solid;
border-width:1px;*/
}
.right
{
width:500px;
position:absolute;
left:600px;
top:-20px;
font-family:Comic Sans, Comic sans MS, cursive;
/*(border-style:solid;
border-width:1px;*/
}
.image
{
position:absolute;
top:70px;
}
.info
{
position:relative;
left:63px;
}
.uniqueInfo
{
position:absolute;
left:250px;
top:42px;
}
.infoRight
{
position:relative;
left:63px;
top:0px;
}
.uniqueInfoRight
{
position:absolute;
left:250px;
top:65px;
}
.imageRight
{
position:absolute;
top:90px;
}
I suspect this might be the problem:
if($count == 5){
echo "<p><br /></p>";
You have 2 per row, and increment $count after every ticket. So, $count = 5 would be after the fourth ticket, or when the third row starts. A sample HTML page would give me a better idea of what's going on exactly, but I'd suggest doing something like
<br style="clear: both;" />
between the rows to split them cleanly. So before ticket 3 and 5 ($count = 3 and $count = 5).

Categories