I have a PHP/HTML page that prints a bunch of receipts. I'm trying to make it page break after each when actually printing. I've tried several style and class codes, but the best I've been able to do is get it to break after the first, but it never repeats. IOW I want it to page break after each time it prints the table referred to in the code.
enter code here
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html><head>
<style type="text/css">
#media all {
.page-break { display: none; }
}
#media print {
.page-break { display: block; page-break-before: always; }
}
</style>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<title>North Atlanta Riding Club</title>
<link href="../styles.css" rel="stylesheet" type="text/css">
<style type="text/css">
<!--
.style45 {
color: #FF0000;
font-weight: bold;
font-style: italic;
}
-->
</style>
</head>
<body>
<?php
do{
//THIS SEES IF THE LOGGED IN MEMBER HAS CONFIRMED CLOTHING
$colname_confirmed = "1";
if (isset($row_roster['key1'])) {
$colname_confirmed = (get_magic_quotes_gpc()) ? $row_roster['key1'] : addslashes($row_roster['key1']);
}
mysql_select_db($database_connection1, $connection1);
$query_confirmed = sprintf("SELECT * FROM clothingorder WHERE who = %s AND confirmed = 'Y' ORDER BY key1 ASC", $colname_confirmed);
$confirmed = mysql_query($query_confirmed, $connection1) or die(mysql_error());
$row_confirmed = mysql_fetch_assoc($confirmed);
$totalRows_confirmed = mysql_num_rows($confirmed);
if($totalRows_confirmed<>0){?>
<table width="990" border="0" align="left" cellpadding="0" cellspacing="0">
<!--DWLayoutTable-->
<tr>
<td width="990" height="31" valign="top"><!--DWLayoutEmptyCell--> </td>
</tr>
<tr>
<td height="83" valign="top">
<table border="1" align="left" cellpadding="2" cellspacing="0" bordercolor="#000000">
<tr bgcolor="#FFFFFF" class="style5">
<td colspan="9"><p>Member- <strong><?php echo $row_roster['fname']." ".$row_roster['lname']; ?><br>
</strong>Telephone- <strong><?php echo $row_roster['tel']; ?></strong> Email- <strong><?php echo $row_roster['email']; ?></strong><br>
Address- <br>
<strong>
<?php if($row_roster['add1']<>''){echo $row_roster['add1']."<br>";} ?>
</strong>
<strong>
<?php if($row_roster['add2']<>''){echo $row_roster['add2']."<br>";} ?>
</strong>
<strong>
<?php if($row_roster['city']<>''){echo $row_roster['city'].", ";} ?>
</strong>
<strong>
<?php if($row_roster['state']<>''){echo $row_roster['state']." ";} ?>
</strong>
<strong>
<?php if($row_roster['zip']<>''){echo $row_roster['zip'];} ?>
</strong><br>
</p>
</td>
</tr>
<tr bgcolor="#FFFFFF" class="style5">
<td><div align="center"><strong>Qty</strong></div></td>
<td><strong>Item</strong></td>
<td><strong>PO?</strong></td>
<td><div align="center"><strong>Paid?</strong></div></td>
<td><div align="center"><strong>Mens/Womens</strong></div></td>
<td><div align="center"><strong>Style</strong></div></td>
<td><div align="center"><strong>Cut</strong></div></td>
<td><div align="center"><strong>Size</strong></div></td>
<td><div align="center"><strong>Price</strong></div></td>
</tr>
<tr bgcolor="#FFFFFF" class="style5">
<td colspan="8"><div align="right">Narc Membership </div></td>
<td><div align="center">
<?php if($row_roster['paid']=="Y"){echo "Paid";$total=0;}else{echo "$".$row_dues['dues'];$total=$row_dues['dues'];} ?></div></td>
</tr>
<?php
do {
$colname_item = "1";
if (isset($row_confirmed['item'])) {
$colname_item = (get_magic_quotes_gpc()) ? $row_confirmed['item'] : addslashes($row_confirmed['item']);
}
mysql_select_db($database_connection1, $connection1);
$query_item = sprintf("SELECT key1, item, price, free FROM clothing WHERE key1 = %s", $colname_item);
$item = mysql_query($query_item, $connection1) or die(mysql_error());
$row_item = mysql_fetch_assoc($item);
$totalRows_item = mysql_num_rows($item);
?>
<tr class="style5">
<td><div align="center"><?php echo $row_confirmed['qty']; ?></div></td>
<td><?php echo $row_item['item']; ?></td>
<td><div align="center"><span class="style45">
<?php if($row_confirmed['postorder']=='Y'){?>YES<?php }?></span></div></td>
<td><div align="center"><?php echo $row_confirmed['paid']; ?></div></td>
<td><div align="center"><?php echo $row_confirmed['mf']; ?></div></td>
<td><div align="center"><?php echo $row_confirmed['style']; ?></div></td>
<td><div align="center"><?php echo $row_confirmed['cut']; ?></div></td>
<td><div align="center"><?php echo $row_confirmed['size']; ?></div></td>
<td><div align="center">
<?php if($row_confirmed['price'] == 0){echo "Free";
}else{
if($row_confirmed['paid']=="Y"){echo "Paid";}else{echo $row_confirmed['price'];$total = $total + $row_confirmed['price'];}
} ?>
</div></td>
</tr>
<?php
} while ($row_confirmed = mysql_fetch_assoc($confirmed)); ?>
<tr bgcolor="#FFFFFF" class="style5">
<td colspan="8"><div align="right"><em><strong>Total Owed</strong></em></div></td>
<td><div align="center" class="style6"><em><strong><?php echo "$".$total.".00";?></strong></em></div></td>
</tr>
</table>
</td>
</tr>
</table>
<div class="page-break"></div>
<?php
}
}while($row_roster = mysql_fetch_assoc($roster));
?>
</body>
I too am finding the page break in #media print {} to be "beyond flaky"! In fact, so far finding the #media print to be flaky entirely. Floats aren't working well and several styling details just don't seem to be displaying as envisioned. It seems that browser support for "print" is lackluster. I am working on an application that should print name badges and precision is critical regarding placement and sizing. I'm close to giving up on the #media print {} styling though I'd hoped to have it look web-savvy online but to print as I envision. Might have to settle for it looking like the badges. I'm using code which adds that page-break class div every 6 "records" (badges are 6-up in 2 columns of 3, 4" x 3" w).
If like me, you're unable to find the method that uses #media print {} would it work to just display the receipt on-screen as you intend it to print? May also be your workaround until (and if) the browsers catch up to w3c conventions. I'd love to find a good publication explaining what does and doesn't work about the #media print styling otherwise the screen styling should work.
Related
First of all my PHP skills are kinda limited, Hence my question to you here.
I have built a fairly complex form with multiple inputs(text boxs and drop downs) which are stored in a MYsql DB. When the form is submitted it displays on a new page as completed reports. These completed reports display one under the next every time the form is submitted. My question is, How can i get the reports displayed to show as a list of links to the individual reports rather then a list of complete reports.
I hope i've explained the situation well enough.
Code snippit from viewpage.php
<html>
<head>
<body>
<?php
mysql_connect("localhost","user","passwrd");
mysql_select_db("dtbase");
$order = "SELECT * FROM jobrequest" ;
$result = mysql_query($order);
while ($row=mysql_fetch_array($result)){
?>
<link rel="stylesheet" href="css/style.css" type="text/css" />
</head>
<body>
<div style="padding:15px 0px 0px 100px;">
<table cellpadding="0" cellspacing="0" border="0" style="vertical-align:middle;width: 1139px; background-color:#213568; height:36px;">
<tr>
<td class="topbar">Client Request Form</td>
<td style="width:900px;"></td>
<td class="topbar"><a style="color:#ffffff;" href="logout.php?logout">Logout</a></td>
</tr>
</table>
<div class="main-wrap">
<div class="content">
<table cellpadding="0" cellspacing="0" border="0" style="width: 1137px; background-color:#ffffff; height:5px;">
<tr>
<td></td>
</tr>
</table>
<table cellpadding="0" cellspacing="0" border="0" >
<tr>
<td style="vertical-align:top; width:5px;"></td>
<td style="vertical-align:top;"><?php include("includes/clientchoices.php"); ?></td>
<td style="vertical-align:top; padding:0px 5px 15px 5px;">
<table border="0" cellpadding="0" cellspacing="0">
<tr>
<td style="vertical-align:top; width:1002px;"> <h1> Dashboard</h1></td>
</tr>
<tr>
<td style="vertical-align:top; background-color:#f5f5f5;"><h2>Job Request Form</h2></td>
</tr>
<tr>
<td style="vertical-align:top; background-color:#ffffff; height:5px;"> </td>
</tr>
<tr>
<td>
<div class="form">
<table cellspacing="0" cellpadding="0" border="0" style="width:998px">
<tr>
<td style="width:1002px; border:solid 1px #000000; padding:10px 0px 10px 0px;"><center><img src="../../images/spectra_logotop.jpg" alt="Spectra" title="Spectra" width="735" height="120" style="padding:5px;"></center>
</td>
</tr>
<tr>
<td>
<div style="padding:10px 0px 10px 0px;">
<table cellpadding="0" cellspacing="0">
<tr>
<td class="headingsa">Project Leader:</td><td class="answersa"><div class= "typesectiona"><?php echo ($row['project_leader'] ); ?></div></td>
<td class="headingsb">Contact Number:</td><td class="answersb"><div class= "typesectionb"><?php echo ($row['contact_number'] ); ?></div></td>
<td class="headingsc">Company Details:</td><td class="answersc"><div class= "typesectionc"><?php echo ($row['company_details'] ); ?></div></td>
</tr>
</table>
</div>
</td>
</tr>
<tr>
<td>
<table cellpadding="0" cellspacing="0">
<tr>
<td class="headings5">Contact Person On Site:</td><td class="answers5"><div class= "typesection5"><?php echo ($row['contactperson_onsite'] ); ?></div></td>
<td class="headings6">Contact Details:</td><td class="answers6"><div class= "typesection6"><?php echo ($row['contact_no'] ); ?></div></td>
<td class="headings7">Date:</td><td class="answers7"><div class= "typesection7"><?php echo ($row['date'] ); ?></div></td>
</tr>
</table>
</td>
</tr>
<tr>
<td>
<table cellpadding="0" cellspacing="0">
<tr>
<td class="headings1">Job/Order Number:</td><td class="answers1"><div class= "typesection1"><?php echo ($row['job_order_number'] ); ?></div></td>
<td class="headings2">Document Number:</td><td class="answers2"><div class= "typesection2"><?php echo ($row['doument_number'] ); ?></div></td>
<td class="headings3">QCP:</td><td class="answers3"><div class= "typesection3"><?php echo ($row['qcp'] ); ?></div></td>
<td class="headings4">Page No:</td><td class="answers4"><div class= "typesection4"><?php echo ($row['pageno'] ); ?></div></td>
</tr>
</table>
</td>
</tr>
<table cellspacing="0" cellpadding="0" border="0">
<tr>
<td width="15px"></td>
<td><a class="othersubmitsLink" href="actionpdf.php">Email to Spectra</a></td>
</tr>
</table>
</div>
</td>
</tr>
</table>
</td>
</tr>
</table>
</div>
</div>
</div>
<?php
}
?>
</body>
</html>
You will need a separate PHP script for displaying a report based on a supplied ID. This separate script would look something like this:
Using mysqli
<?php
$conn = new mysqli("localhost", "user", "passwrd", "dtbase");
$jrQry = $conn->prepare("SELECT * FROM jobrequest WHERE jobrequest_id = ?");
$jrQry->bind_param('i', $_GET['jobrequest_id']);
$jrQry->execute();
$jobrequestResult = $jrQry->get_result();
$jobrequest = $jobrequestResult->fetch_assoc();
// At this point, $jobrequest will contain the jobrequest record you want to display.
?>
<!-- HTML FOR REPORT GOES HERE, USING $jobrequest VARIABLE TO SHOW THE DATA -->
Note that I have used mysqli in this example, if this is unsuitable you can use the old-style mysql commands, but for many many reasons (security chief among them) I would strongly suggest against this.
Using mysql
<?php
mysql_connect("localhost","user","passwrd");
mysql_select_db("dtbase");
$order = "SELECT * FROM jobrequest WHERE jobrequest_id = " . (int)$_GET['jobrequest_id'];
$result = mysql_query($order);
$jobrequest = mysql_fetch_array($result);
// At this point, $jobrequest will contain the jobrequest record you want to display.
?>
<!-- HTML FOR REPORT GOES HERE, USING $jobrequest VARIABLE TO SHOW THE DATA -->
Save this page as "viewjobrequest.php" and you will be able to load a given job request's report by supplying the jobrequest ID as a parameter in the URL, like so:
http://address_of_site/viewjobrequest.php?jobrequest_id=X
Now you can automatically generate a list of links to these pages by looking up your complete set of jobrequests and iterating over them, but instead on outputting a full report, just output a link:
Using mysqli
<?php
$conn = new mysqli("localhost", "user", "passwrd", "dtbase");
$jrQry = $conn->prepare("SELECT * FROM jobrequest WHERE jobrequest_id = ?");
$jrQry->bind_param('i', $_GET['jobrequest_id']);
$jrQry->execute();
$jobrequestResult = $jrQry->get_result();
?>
<ul>
<?php
while ($jobrequest = $jobrequestResult->fetch_assoc())
{
?>
<li>
<a href="viewjobrequest.php?jobrequest_id=<?php echo $jobrequest['jobrequest_id']; ?>">
View job request #<?php echo $jobrequest['jobrequest_id']; ?>
</a>
</li>
<?php
}
?>
</ul>
Using mysql
<?php
mysql_connect("localhost","user","passwrd");
mysql_select_db("dtbase");
$order = "SELECT * FROM jobrequest WHERE jobrequest_id = " . (int)$_GET['jobrequest_id'];
$result = mysql_query($order);
?>
<ul>
<?php
while ($jobrequest = mysql_fetch_assoc($result))
{
?>
<li>
<a href="viewjobrequest.php?jobrequest_id=<?php echo $jobrequest['jobrequest_id']; ?>">
View job request #<?php echo $jobrequest['jobrequest_id']; ?>
</a>
</li>
<?php
}
?>
</ul>
Note: I have deliberately omitted large portions of your HTML, you can add as much extra HTML as you need, I've just offered the bare bones to get you started.
BY looking at your code, I can say, it's not problem with PHP, it's more like HOW you are showing the result after fetching from database,
you are running loop, started from here
<?php while ($row=mysql_fetch_array($result)){ ?>
and ends here
<?php}?>
So everything inside loop or in easy words inside these brackets {} repeating again and again with new row of result fetched from database, if you take view source of viewpage.php you will see that style css file <link rel="stylesheet" href="css/style.css" type="text/css" /> repeating, Imagine if you are fetching 10 rows of result, you are also loading css file 10 times.
So the answer (most probably the solution) of your question is;
Your mysql query
<?php
mysql_connect("localhost","user","passwrd");
mysql_select_db("dtbase");
$order = "SELECT * FROM jobrequest" ;
$result = mysql_query($order);
$totalrows = mysql_num_rows($result); //Check Total Number of Rows To Check if Data Exist or Not
?>
and then in your HTML, First check if there are any rows exist in database which match your WHERE clause in mysql query.
//Set an if else statement here so incase if no data exist.
<?php if($totalrows > 0) {
//If row(s) exist run your while loop here
<?php while ($row=mysql_fetch_array($result)){ ?>
//Show the result here from database
//Close your loop
<?php } ?>
//Close your if condition
<?php } else { ?>
//Display a message here if there is no data to show
//Close your else bracket
<?php } ?>
With above explaniation I adjusted your HTML to show the result in desired way;
<table cellspacing="0" cellpadding="0" border="0" style="width:998px">
<tr>
<td style="width:1002px; border:solid 1px #000000; padding:10px 0px 10px 0px;"><center><img src="../../images/spectra_logotop.jpg" alt="Spectra" title="Spectra" width="735" height="120" style="padding:5px;"></center></td>
</tr>
<tr>
<td>
<?php if($totalrows > 0) {
<div style="padding:10px 0px 10px 0px;">
<table cellpadding="0" cellspacing="0">
<tr>
<td class="headingsa">Link to Report</td>
</tr>
<?php while ($row=mysql_fetch_array($result)){ ?>
<tr>
//You have to replace `nameoffile.php` with file in which you want to display report and correct this (as i assumed it) if it's wrong `$row['id']`
<td>Open Report</td>
</tr>
<?php } ?>
</table>
</div>
<?php } else { ?>
<div style="padding:10px 0px 10px 0px;">
<table cellpadding="0" cellspacing="0">
<tr>
<td>There is No Result To Show</td>
</tr>
</table>
</div>
<?php } ?>
</td>
</tr>
</table>
Note: MySQL will soon be deprecated, consider start using MYSQLi or PDO
I'm going nuts to try to understand why the script below (let's call it script1 is passing session variable $_SESSION['emptystcode'] to bulkstOLD.php but not the other two: $_SESSION['dlstrest'] and $_SESSION['dllist']. I have session_start(); on the first command line of the called script.
All this script1 does is to $_GET the Restaurant and List names and display a form where the user can fill in a CODE field and submit it.
To makes things worse, I've created another script (a simplified version of this caller script) which just set the session variables and calls the same bulkstOLD.php and it works ok. I wonder if this has something to do with the $_GET. Any help would be much appreciated.. Thanks!!
Here is the code:
<?php
session_start();
include ('logged.php');
require_once ('functions.php');
$acisversion = $_SESSION['acisversion'];
reset_all();
$cyear = date(Y);
$cmonth = date(M);
$cday = date(d);
$configs = include('config.php');
$_SESSION["module"] = 'st';
$_SESSION['favstlists_ref'] = 0;
$strest = $dlstrest = $_GET['dlstrest'];
$favstlist = $dllist = $_GET['dllist'];
$restname = 'restname_'.$strest;
$stlistrest = $configs[$restname];
?>
<!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>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"/>
<title>ACIS - Edit Lists</title>
<script type="text/javascript" src="jquery-1.11.0.min.js"></script>
<script type="text/javascript" src="stmenu.js"></script>
<style type="text/css">
#import url(acis.css);
</style>
<script type="text/javascript" src="js.js"></script>
</head>
<body>
<div id="content">
<?php
$_SESSION['stcodesub'] = $stcodesub = $stcode = ($_POST["stcodein"]);
dbfile_init() ;
$_SESSION['stcode'] = $stcode;
if(isset($_POST["editSave"]))
{
connect_db ();
if (!empty($stcode))
{
check_code_for_st_list();
$emptystcode = 0;
}
else
{
$emptystcode = 1;
}
$_SESSION['dlstrest'] = $dlstrest;
$_SESSION['dllist'] = $dllist;
$_SESSION['emptystcode'] = $emptystcode;
if ((!$emptystcode and $codestok) or $emptystcode)
{
echo '<META HTTP-EQUIV="Refresh" Content="0; URL=bulkstOLD.php">';
exit;
}
}
?>
<table width="100%" border="0" align="center">
<tr>
<td width="223" align="left"></td>
<td width="111" align="right"></td>
</tr>
</table>
</style>
<form method="post" id="editLists" action="<?php echo htmlspecialchars($_SERVER["PHP_SELF"]);?>">
<table width="739" border="0" align="center" cellspacing="0" bgcolor="#171717">
<tr>
<td colspan="3"
style="color:#00CC00;
text-align: left;
padding: 0;
background: #2e2e2e url(images/nav_bar.jpg) repeat-x;
font-size: 0.9em;
color: white;
height:16px;"><script type="text/javascript" src="mainmenu.js"></script></td>
</tr>
<tr>
<td width="502"><h2 style="color:red;"> Atualizar Listas Favoritas de Pratos</h2></style></td>
<td width="231" colspan="2" align="right"><?php echo $configs[footer];?></td>
</tr>
<tr>
<td colspan="3" align="right" ><table width="100%" border="0" align="center">
<tr>
<td align="center">Restaurante:</td>
<td width="84" align="center" valign="bottom">Adicionar Código</td>
<td width="350" align="center">Lista a ser atualizada:</td>
<td width="150" align="left" valign="bottom"><span class="error"><?php echo $favErr;?></span></td>
</tr>
<tr>
<td width="135" align="center"><b><?php echo $stlistrest; ?></b></td>
<td align="center">
<?php
echo $stcodeline;
?>
</td>
<td align="center"><b><?php echo $dllist; ?></b></td>
<td align="right"><input type="submit" name="editSave" style="background-color: #009900; color: #FFFFFF;" value="Submeter" /></td>
</tr>
</table></td>
</tr>
</table>
</form>
<?php
$_SESSION["module"] = 'st';
?>
</div>
</body>
</html>
The only possible explanation for your problem is that you might have not written <?php session_start();?> in the very beginning, before any HTML tags(even doctype). Write it on top of every relevant php document.
Look if all your files are saved as UTF-8 without BOM, not just UTF-8.
This BOM dissables sessions.
And look if all your files are called as they are in the same subdomain.
www.domain.com/file1.php,
ww2.domain.com/file2.php,
domain.com/file3.php
... with diferent subdomains should not work.
Trying to make a simple site where users can have different account levels.
For example, user with account type 'a' and 'b' will see a Link/button at the top which says basic and the users with account type 'c' will see a Link/button which says full member.
I have a code which will almost do what I need and it will save the users in different A/B/C categories in the database.
I just need to know what I have to do to be able to show different links to different account type as I explained above?
also, I know the code bellow is not the greatest codes but just need to achieve the results I am after for now with what I have.
<?php
session_start(); // Must start session first thing
// See if they are a logged in member by checking Session data
$toplinks = "";
if (isset($_SESSION['id'])) {
// Put stored session variables into local php variable
$userid = $_SESSION['id'];
$username = $_SESSION['username'];
$toplinks = '' . $username . ' •
Account •
Log Out';
} else {
echo 'Please log in to access your account';
exit();
}
?>
<?php
//Connect to the database through our include
include_once "scripts/connect_to_mysql.php";
// Query member data from the database and ready it for display
$sql = mysql_query("SELECT * FROM members WHERE id='$userid'");
while($row = mysql_fetch_array($sql)){
$country = $row["country"];
$state = $row["state"];
$city = $row["city"];
$accounttype = $row["accounttype"];
$bio = $row["bio"];
}
// Give different options or display depending on which user type it is
if ($accounttype == "a") {
$userOptions = "You get options for Expert User";
} else if ($accounttype == "b") {
$userOptions = "You get options for Expert User";
} else if ($accounttype == "c") {
$userOptions = "You get options for Expert User";
} else {
$userOptions = "You get options for Super User";
}
?>
<!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>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Member Account</title>
<link rel="stylesheet" type="text/css" href="style/style.css">
<style type="text/css">
<!--
body {
margin: 0px;
background-image: url(imgs/bgnoise.png);
background-repeat: repeat;
}
-->
</style>
</head>
<body>
<?php include_once("temps/template_header.php");?>
<table style="background-image: url(imgs/horizontal_nav_bg.jpg);" repeat="x" width="100%" border="0" cellpadding="0">
<tr>
<td height="94" ><table style=" margin-left:20px; " width="734" border="0" cellspacing="0" cellpadding="0">
<tr>
<td width="156"><p><img src="imgs/info.png" width="35" height="35" border="0" "/>Edit Information</p></td>
<td width="179"><img src="imgs/very.png" width="35" height="35" border="0" />Verify Your Identity</td>
<td width="126"><img src="imgs/profile.png" width="35" height="35" border="0" />View Profile</td>
<td width="138"><img src="imgs/basket.png" width="35" height="35" />Buy Bitcoin</td>
<td width="135"><img src="imgs/user.png" width="35" height="35" alt="user" /><?php echo "$username"; ?></td>
</tr>
</table> <h1> </h1></td>
</tr>
</table>
<table width="700" align="right" border="0" cellspacing="0" cellpadding="0">
<tr>
<td><h3></h3></td>
</tr>
</table>
<table width=950" cellpadding="3" cellspacing="3" style="line-height:1.5em;">
<tr>
<td width="118" valign="top" bgcolor="#E4E4E4"><h6>YOUR ACCOUNT<br />
Edit Information <br />
Verify Your Identity<br />
View Profile</h6>
<h6><?php echo "$bio"; ?><br />
</h6></td>
<!-- See the more advanced member system tutorial to see how to place default placeholder pic until member uploads one -->
<td width="160" valign="top"><div align="center"><img src="memberFiles/<?php echo "$userid"; ?>/pic1.jpg" alt="Ad" width="150" /></div></td>
<td width="201" valign="top">
Country: <?php echo "$country"; ?> <br />
State: <?php echo "$state"; ?><br />
City: <?php echo "$city"; ?>
<table width="50" border="0" cellspacing="0" cellpadding="0">
<tr>
</tr>
</table> <br />
</td>
<td width="430" margin="left" style="margin-right:0px;" rowspan="2" valign="top"><div id="veri"><img src="imgs/verifynote.png" width="430" height="600" /> </div></td>
</tr>
<tr>
<td colspan="3" valign="top"><br />
<br />
<br />
<div style="overflow:hidden; width:100%px;">
<iframe width="565" height="400" scrolling="no" frameBorder="0"
src="http://bitcoin.clarkmoody.com/widget/chart/"
style="width:728px; height:270px; border:none; margin-left:-60px;"/>
</div>
</td>
</tr>
</table>
<?php include_once("temps/template_footer.php");?>
</body>
</html>`
Please be gentle as I am a newbie in PHP and just learning the curves.
Thanks
I am not sure if I got this correctly but if you want according to the user's group to display different links just do:
if ($accounttype == "a") {
echo 'Page for user a';
}
else if ($accounttype == "b") {
echo 'Page for user b';
} else if ($accounttype == "c") {
echo 'Page for user c';
} else {
echo 'Page for others';
}
Also I suggest you to use mysqli. It is pretty similar to mysql. http://php.net/manual/en/book.mysqli.php (Myqsl is being removed)
I have a Table already written in PHP that echos out data called from the database like so:
<TABLE cellSpacing=1 cellPadding=2 align=center bgColor=#aaaaaa border=0 width="100%" class="logintbl">
<TR>
<TD bgColor=whitesmoke colSpan=0><B>Pages</B></td>
</tr>
<tr>
<td>
<table align="center" cellSpacing=0 cellPadding=2 border="0" width="100%">
<tr>
<td align="center" valign="bottom"> <font color="#4d71a1"><b>Page Name</b></font> </td>
</tr>
<?php while ($row = mssql_fetch_array($result)) { ?>
<tr bgcolor="#eeeeee">
<td align="center"><?php echo $row["PageURL"]; ?></td>
<td align="center">
<img src="images/0013-pen.gif" width="16" height="16" alt="" border="0">
</td>
</tr>
<?php } ?>
<tr><td colspan="7"> </td></tr>
<tr>
<td colspan="7" align="center">
</td>
</tr>
</table>
</td>
</tr>
</table>
I have been trying to alternate the colours of the rows, using a snippet of PHP and after some research implemented this:
<tr bgcolor="<?php echo ($clrCounter++ % 2 == 0 ? '#000000' : '#ffffff'); ?>">
It doesn't seem to work correctly, so I feel I am going wrong somewhere, I know there is longer ways to implement this that I could implement. I was just hoping for something simple. Am I wasting effort trying to implement it this way?
I integrated it as follows:
<TABLE cellSpacing=1 cellPadding=2 align=center bgColor=#aaaaaa border=0 width="100%" class="logintbl">
<TR>
<td bgColor=whitesmoke colSpan=0><B>Pages</B></td>
</tr>
<tr>
<td>
<table align="center" cellSpacing=0 cellPadding=2 border="0" width="100%">
<tr bgcolor="#3A7525">
<td align="center" valign="bottom"> <font color="#4d71a1"><b>Page Name</b></font> </td>
</tr>
<?php while ($row = mssql_fetch_array($result)) { ?>
<tr bgcolor="<?php echo ($clrCounter++ % 2 == 0 ? '#C2C2C2' : '#ffffff'); ?>">
<td align="center"><?php echo $row["PageURL"]; ?></td>
<td align="center">
<img src="images/0013-pen.gif" width="16" height="16" alt="" border="0">
</td>
</tr>
<?php } ?>
<tr>
<td colspan="7" align="center">
</td>
</tr>
</table>
</td>
</tr>
</table>
It sort of works, but for some reason the very first entry is blue? When I've specified white and grey.
You could use the following when looping through the results returned from your db:
<?php
// Define row colors
$color1 = "#FFFFFF";
$color2 = "#F4F9FF";
// Set row counter
$row_count = 0;
while ($row = mssql_fetch_array($result)) {
$row_color = ($row_count % 2) ? $color1 : $color2;
?>
<tr bgcolor="<?php echo $row_color; ?>">
<td align="center"><?php echo $row["PageURL"]; ?></td>
<td align="center">
<img src="images/0013-pen.gif" width="16" height="16" alt="" border="0">
</td>
</tr>
<?php
$row_count++;
}
?>
Alternatively, you could replace the bgcolor tags and assign a CSS class to each row.
Use the CSS selector :nth-of-type( ).
By putting different styles for both the :nth-of-type(even) and :nth-of-type(odd) the browser does the alternating styling for you, so you won't have to worry about it.
See the W3Schools entry on this.
Try This:
<tr <?php if($i%2){?>bgcolor="#eeeeee"<?php } else{ ?>bgcolor="red" <?php } $i++; ?>>
Thanks to Bas van den Heuvel for the great answer using CSS. If you encountered extra line spacing like I did, and want to remove it, use the following example code. This will make the alternating color lines be tighter together. (I used light grey and white)
p:nth-of-type(odd)
{
background:#e2e2e2;
margin: 0px;
padding: 0px;
}
p:nth-of-type(even)
{
background:#ffffff;
margin: 0px;
padding: 0px;
}
i am working on a project which is airways ticketing.
i am able to display the final ticket to the user but how can i give user the ability to print it when he/she clicks on print button.
please help..
<title>Untitled Document</title>
<style type="text/css">
#main {
position:absolute;
top:100px;
width:100%;
height:250px;
z-index:1;
}
#submit {
position:absolute;
top:300px;
width:100%;
height:42px;
z-index:2;
}
</style>
</head>
<body>
<div id="main" align="center">
<?PHP
mysql_connect("127.0.0.1","root","");
mysql_select_db("cmc");
$id=$_REQUEST['id'];
$r=mysql_query("select * from manifest where transid=".$id);
$d=mysql_fetch_assoc($r);
?>
<table width="800" border="1">
<tr>
<td colspan="6" align="center">HORIZON AIRWAYS PASSENGER TICKET</td>
</tr>
<tr >
<td colspan="3" align="center">PNR NUMBER: </td>
<td colspan="3" align="center"><?php echo $d["pnrno."]; ?></td>
</tr>
<tr >
<td colspan="3" align="center"> PASSENGER'S NAME:</td>
<td colspan="3" align="center"><?php echo $d["name"]; ?></td>
</tr>
<tr >
<td colspan="3" align="center">DATE OF ISSUE:</td>
<td colspan="3" align="center"><?PHP
ini_set('date.timezone','asia/calcutta');
echo date("d/m/y"); ?></td>
</tr>
<tr >
<td colspan="3" align="center">TIME OF ISSUE:</td>
<td colspan="3" align="center"><?PHP
echo date("h/i/s"); ?></td>
</tr>
<tr >
<td colspan="3" align="center">DATE OF JOURNEY:</td>
<td colspan="3" align="center"><?php echo $d["day"]."-".$d["month"]."-".$d["year"]; ?> </td>
</tr>
<tr>
<td colspan="6" align="center">NOT TRANSFERRABLE</td>
</tr>
<tr>
<td colspan="3" align="center">PASSENGER NAME:</td>
<td colspan="3" align="center"><?php echo $d["name"]; ?></td>
</tr>
<tr>
<td colspan="3" align="center">SECTOR:</td>
<td colspan="3" align="center"><?php echo $d["sector"]; ?></td>
</tr>
<tr>
<td width="134" align="center">FLIGHT #</td>
<td width="132" align="center">CLASS</td>
<td width="112" align="center">DATE</td>
<td width="130" align="center">DEP. TIME</td>
<td width="132" align="center">ARR. TIME</td>
<td width="120" align="center">STATUS</td>
</tr>
<tr>
<td><?php echo $d["flight_no."]; ?></td>
<td><?php echo $d["class"]; ?></td>
<td><?php echo $d["name"]; ?></td>
<td><?php echo $d["departure"]; ?></td>
<td><?php echo $d["arrival"]; ?></td>
<td><?php echo "confirm"; ?></td>
</tr>
</table>
<div id="submit" align="center">
<form name="form1" method="POST">
<input type="submit" value="Print" name="submit"/>
</form>
</div>
</div>
</body>
</html>
Printing has to be done on the client side, not the server side. This shouldn't be a form (I would actually make it a link). The simplest method:
<input type="submit" value="Print" onclick="print(); return false;"/>
You can trigger the print event bij using the javascript function: window.print().
Example:
print page
TIP!
Use a print CSS to tell the browser what to print! That way the user doesn't waste paper ;)
Example including a print CSS stylesheet: <style type="text/css" media="print" href="print.css" />
More info about CSS print stylesheets: http://www.alistapart.com/articles/goingtoprint/
You can invoke printing via javascript using print method
Click to Print This Page
You might want to hide certain elements in page when printing it. For that you can use css like so:
#media print {
.non-printable { display: none; }
}
And then give non-printable class to those elements that you don't want printed.
The others are correct that this would be done with
print ticket
You will also probably want to create a separate CSS style for the print version that strips out unnecessary graphics. You can also add manual page breaks in case there are individual boarding passes or something.
<link rel="stylesheet" href="css/print.css" type="text/css" media="print" />