I have this css styling and was wondering what I need to change in order to collapse/hide html tables that are empty.
The style:
<style>
#search_settings
{
position:relative;
height:25px;
width:500px;
}
#users_table_results
{
border-collapse:separate;
empty-cells:hide;
}
#events_table_results
{
border-collapse:separate;
empty-cells:hide;
}
#establishments_table_results
{
border-collapse:separate;
empty-cells:hide;
}
</style>
My HTML:
<div id="search_settings">
<table width="500" border="0">
<tr>
<td height="20" class="heading_text_18">Search results</td>
</tr>
</table>
<table id="users_table_results" max-width="500" name="users" border="0">
<tr>
<td width="50" height="50"><a href="#profile.php"><img src="Images/<?php echo $row_result_users['picture_thumb_url']; ?>"
border="0" height="50" width="50"/></a></td>
<td width="150" class="ordinary_text_12"><?php echo $row_result_users['user_first_name']; ?></td>
<td width="150" class="ordinary_text_12"><?php echo $row_result_users['user_last_name']; ?></td>
<td width="150" class="ordinary_text_12"><?php echo $row_result_users['username']; ?></td>
</tr>
</table>
<table id="events_table_results" width="500" name="events" border="0">
<tr>
<td width="50" height="50"><a href="#profile.php"><img src="Images/<?php echo $row_event['event_thumb_url']; ?>"
border="0" height="50" width="50"/></a></td>
<td width="150" class="ordinary_text_12"><?php echo $row_event['event_name']; ?></td>
<td width="150" class="ordinary_text_12"><?php echo $row_event['event_venue']; ?></td>
<td width="150" class="ordinary_text_12"><?php echo $row_event['event_date']; ?></td>
</tr>
</table>
<table id="establishments_table_results" width="500" name="establishments" border="0">
<tr>
<td width="50" height="50"><a href="#profile.php"><img src="Establishment_Images/<?php echo $row_establishment['establishment_thumb_url']; ?>"
border="0" height="50" width="50"/></a></td>
<td width="150" class="ordinary_text_12"><?php echo $row_establishment['establishment_name']; ?></td>
<td width="150" class="ordinary_text_12"><?php echo $row_establishment['location_name']; ?></td>
<td width="150" class="ordinary_text_12"><?php echo $row_establishment['establishment_pricing']; ?></td>
</tr>
</table>
</div>
I would want it such that if there are no results for my events table, the table does not show(there is no blank space between search results where event results should be because border=0). Can you hide entire tables?
Why not wrap the entire table in a PHP if statement and then use that to check for data and display the table or not?
If you wanted to keep your client side HTML free of server side markup and help keep content and behavior 100% separate, you could use JQuery to hide any tables for which there are no row elements found:
$(document).ready( function() {
$('table').each( function() {
if( $(this).find('tr').length == 0 ) {
$(this).hide();
}
});
});
The best method is to use a server side language like to PHP to generate the required table based on the SQL query. This will result in shorter and more effective code.
If you want to achieve this just using css and your existing code, you could create a new css class called hidden_table and set display to none:
.hidden_table {
display: none;
}
Then in your output, you can determine whether to write the css class of the table as your standard class if there are rows, or you can give the table the class "hidden_table" which will hide the entire table.
Related
My trying to show product desc in pop up. Mean when i click on product link then one pop up will open and show product desc. but here something is wrong. every product link showing first product desc. My code is Below. Please help me out.
Javascript:
<script language="JavaScript">
function displayPopup(alert_MSG)
{
var theDetail = document.getElementById('flyBox');
theDetail.style.display="block";
}
function closePopup(alert_MSG)
{
var theDetail = document.getElementById('flyBox');
if (theDetail.style.display=="block")
{
theDetail.style.display="none";
}
}
</script>
HTML:
View larger
<div id="flyBox" style="display:none;">
<table width="100%" height="100%" border="0" cellspacing="0" cellpadding="0">
<tr>
<td align="center">
<table border="0" cellspacing="0" cellpadding="0">
<tr>
<td class="borderWindow">
<div class="container">
<div id="closeButton"><img src="http://i1122.photobucket.com/albums/l523/Long_Islander/flyBoxClose.png" width="28" height="28" alt="Close Button" border="0" /></div>
<div class="content">
<table width="600" border="0" cellspacing="20" cellpadding="0">
<tr>
<td>
<div id="myMessageBox" name="myMessageBox">
<table width="100%" border="0" cellspacing="2" cellpadding="0">
<tr>
<td class="colheadingL"><font color="white">Description</font></td>
</tr>
<tr>
<td ><?php echo $img; ?></td>
<td>Book Name:</td>
<td ><?php echo $row['pname']; ?></td>
<td class="text1">MRP:</td>
<td><?php echo $row['price'];?> </td>
</tr>
</table>
</div>
</td>
</tr>
</table>
</div>
</div>
</td>
</tr>
</table>
</td>
</tr>
</table>
</div>
But pop up is open click on hyperlink. but problem is showing only 1'st record in all product
You don't have loop any in your template script, that is why you see just one record vizualized.
I don't know exactly how your code is organized outside of the snippet you have posted, but assuming your data rows are in $rows array variable, the code will look something like that:
<? foreach($rows as $row) { ?>
<tr>
<td ><?php echo $img; ?></td>
<td>Book Name:</td>
<td ><?php echo $row['pname']; ?></td>
<td class="text1">MRP:</td>
<td><?php echo $row['price'];?> </td>
</tr>
<? } ?>
Try to make IDs of each DIV as Unique.
Below is the sample code, try to use it as per your requirement
<script language="JavaScript">
function displayPopup(id)
{
var theDetail = document.getElementById(id);
theDetail.style.display="block";
}
function closePopup(id)
{
var theDetail = document.getElementById(id);
if (theDetail.style.display=="block")
{
theDetail.style.display="none";
}
}
</script>
<?php for($i=0;$i<4;$i++){?>
<div>
View larger
<div id="flyBox_<?php echo $i;?>" style="display:none;">
<div id="closeButton"><img src="http://i1122.photobucket.com/albums/l523/Long_Islander/flyBoxClose.png" width="28" height="28" alt="Close Button" border="0" /></div>
<table width="100%" height="100%" border="0" cellspacing="0" cellpadding="0">
<tr>
<td align="center">
<?php echo "Div ".$i. " Content comes here";?>
</td>
</tr>
</table>
</div>
</div>
<?php }?>
Old ASP developer migrating to PHP. I writ a PHP script to retrieve entries from an MS SQL Database and display. Looks like this:
<?php
$query = "SELECT DateUploaded, Title ";
$query .= "FROM TableName ";
$result = mssql_query($query);
$numRows = mssql_num_rows($result);
echo "<h1>" . $numRows . " Row" . ($numRows == 1 ? "" : "s") . " Returned </h1>";
while($row = mssql_fetch_array($result))
{
echo "<li>" . $row["DateUploaded"] . $row["Title"] . "</li>";
}
?>
Now when I want to get it to display echoing it just on the page works fine. Using this section of code:
while($row = mssql_fetch_array($result))
{
echo "<li>" . $row["DateUploaded"] . $row["Title"] . "</li>";
}
However when I try and put it into a table Ive created to display it it doesn't seem to work, although I've read a few tutorials and feel it should, it is also similar to a technique I used to use in ASP.
Looks like this:
<TABLE cellSpacing=1 cellPadding=2 align=center bgColor=#aaaaaa border=0 width="100%" class="logintbl">
<TR>
<TD bgColor=whitesmoke colSpan=0><B>News</B></td>
</tr>
<tr>
<td bgColor=#ffffff>
<table align="center" cellSpacing=0 cellPadding=2 border="0" width="100%">
<tr>
<td align="center" valign="bottom"> <font color="#4d71a1"><b>Date Uploaded</b></font> </td>
<td align="center" valign="bottom"> <font color="#4d71a1"><b>News Title</b></font> </td>
<td align="center"></td>
</tr>
<tr bgcolor="#eeeeee">
<tr bgcolor="#ffffff">
<td align="center"><?php echo $row["DateUploaded"]; ?></td>
<td align="center"><?php echo $row["Title"]; ?></td>
<td align="center">
<img src="images/0013-pen.gif" width="16" height="16" alt="" border="0">
<a href="NewsManage.php?do=del&id=" return false;">
<img src="images/1001-cancel16.gif" width="16" height="16" alt="" border="0">
</a>
</td>
</tr>
<tr><td colspan="7"> </td></tr>
<tr>
<td colspan="7" align="center">
</td>
</tr>
</table>
</td>
</tr>
</table>
I'm probably doing it totally wrong, but could someone point me in the right direction please?
Put the row into echo inside your loop:
<?php
while($row = mssql_fetch_array($result))
{
echo '<tr bgcolor="#ffffff">
<td align="center">'.$row["DateUploaded"].'</td>
<td align="center">'.$row["Title"].'</td>
<td align="center">
<img src="images/0013-pen.gif" width="16" height="16" alt="" border="0">
<img src="images/1001-cancel16.gif" width="16" height="16" alt="" border="0">
</td>
</tr>';
}
?>
Start the while loop right before the row with the data,
and end it right after that.
<table align="center" cellSpacing=0 cellPadding=2 border="0" width="100%">
<!-- header row here -->
<?php
$alterColor = true;
while ($row = mssql_fetch_array($result)) { // start while
// alternating bg color for rows
$color = ($alterColor) ? "#fff" : "#eee";
$alterColor = !$alterColor;
?>
<tr bgcolor="<?php echo $color; ?>">
<td align="center"><?php echo $row["DateUploaded"]; ?></td>
<td align="center"><?php echo $row["Title"]; ?></td>
<td align="center">
<img src="images/0013-pen.gif" width="16" height="16" alt="" border="0">
<a href="NewsManage.php?do=del&id=" return false;">
<img src="images/1001-cancel16.gif" width="16" height="16" alt="" border="0">
</a>
</td>
</tr>
<?php } // end while ?>
</table>
PS One of these seems to be extra, are they there for alternating color or something like that:
<tr bgcolor="#eeeeee">
<tr bgcolor="#ffffff">
You should not really have a tr within a tr directly.
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" />
in this code i want to add $image variable to td background but i dont know if add it between quotes without any problems..or delete quotes..and how to get it from youtube video..thanks for helping
<table width="130" height="97">
<tbody><tr>
<td valign="center" width="130" align="center" background="showvideo.php_files/2_003.jpg" height="97">
<a href="http://www.mysite.com/video/watch.php?VDCID=42608">
<img src="showvideo.php_files/play_arrow.gif" alt=" Theme Song " border="0">
</a>
</td>
</tr>
</tbody></table>
there you go:
<td valign="center" width="130" align="center" background="<?php echo $image; ?>" height="97"></td>