TalkPHP
 
 
Account Login
Latest Articles
» The basic usage of PHPTAL, a XML/XHTML template library for PHP
» Vulnerable methods and the areas they are commonly trusted in.
» Simple way to protect a form from bot
» The Basics On: How Session Stealing Works
» How to keep your forms from double posting data
IRC Channel
IRC Speech Bubble Join the friendly bunch on IRC...
(#TalkPHP on Freenode)

...Also available via a web interface.

See this thread for information on the TalkPHP Free Hugs Initiative™. Subject to availability.
Associates
Associates
CSS Tutorials
Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old 08-19-2008, 08:00 PM   #1 (permalink)
The Wanderer
 
frosty's Avatar
 
Join Date: Aug 2008
Location: texas
Posts: 13
Thanks: 3
frosty is on a distinguished road
Help Ok, my first real issue!!

I am looking for an "easy" (nothing is easy right) way to alternate the row colors in the code block below...

PHP Code:

<?php require_once('../Connections/add.php');

if (!
function_exists("GetSQLValueString")) {
function 
GetSQLValueString($theValue$theType$theDefinedValue ""$theNotDefinedValue ""
{
  
$theValue get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue;

  
$theValue function_exists("mysql_real_escape_string") ? mysql_real_escape_string($theValue) : mysql_escape_string($theValue);

  switch (
$theType) {
    case 
"text":
      
$theValue = ($theValue != "") ? "'" $theValue "'" "NULL";
      break;    
    case 
"long":
    case 
"int":
      
$theValue = ($theValue != "") ? intval($theValue) : "NULL";
      break;
    case 
"double":
      
$theValue = ($theValue != "") ? "'" doubleval($theValue) . "'" "NULL";
      break;
    case 
"date":
      
$theValue = ($theValue != "") ? "'" $theValue "'" "NULL";
      break;
    case 
"defined":
      
$theValue = ($theValue != "") ? $theDefinedValue $theNotDefinedValue;
      break;
  }
  return 
$theValue;
}
}

$currentPage $_SERVER["PHP_SELF"];

$maxRows_TerminalList 50;
$pageNum_TerminalList 0;
if (isset(
$_GET['pageNum_TerminalList'])) {
  
$pageNum_TerminalList $_GET['pageNum_TerminalList'];
}
$startRow_TerminalList $pageNum_TerminalList $maxRows_TerminalList;

mysql_select_db($database_jpbdadd$jpbdadd);
$query_TerminalList "SELECT * FROM xx";
$query_limit_TerminalList sprintf("%s LIMIT %d, %d"$query_TerminalList$startRow_TerminalList$maxRows_TerminalList);
$TerminalList mysql_query($query_limit_TerminalList$jpbdadd) or die(mysql_error());
$row_TerminalList mysql_fetch_assoc($TerminalList);

if (isset(
$_GET['totalRows_TerminalList'])) {
  
$totalRows_TerminalList $_GET['totalRows_TerminalList'];
} else {
  
$all_TerminalList mysql_query($query_TerminalList);
  
$totalRows_TerminalList mysql_num_rows($all_TerminalList);
}
$totalPages_TerminalList ceil($totalRows_TerminalList/$maxRows_TerminalList)-1;

$queryString_TerminalList "";
if (!empty(
$_SERVER['QUERY_STRING'])) {
  
$params explode("&"$_SERVER['QUERY_STRING']);
  
$newParams = array();
  foreach (
$params as $param) {
    if (
stristr($param"pageNum_TerminalList") == false && 
        
stristr($param"totalRows_TerminalList") == false) {
      
array_push($newParams$param);
    }
  }
  if (
count($newParams) != 0) {
    
$queryString_TerminalList "&" htmlentities(implode("&"$newParams));
  }
}
$queryString_TerminalList sprintf("&totalRows_TerminalList=%d%s"$totalRows_TerminalList$queryString_TerminalList);
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>

<style type="text/css">
<!--
.style3 {font-family: Verdana, Arial, Helvetica, sans-serif; font-size: xx-small; }
.style5 {font-family: Verdana, Arial, Helvetica, sans-serif; font-size: xx-small; color: #990000; }
-->
</style>
</head>

<body>
<table border="0" cellpadding="0" cellspacing="2">
  <tr>
    <td bgcolor="#CCCCCC" class="style3">&nbsp;Record ID&nbsp;</td>
    <td bgcolor="#CCCCCC" class="style3">&nbsp;Description&nbsp;</td>
    <td bgcolor="#CCCCCC" class="style3">&nbsp;Device Type&nbsp;</td>
    <td bgcolor="#CCCCCC" class="style3">&nbsp;Model No.&nbsp;</td>
    <td bgcolor="#CCCCCC" class="style3">&nbsp;Application&nbsp;</td>
    <td bgcolor="#CCCCCC" class="style3">&nbsp;Dial Up&nbsp;</td>
    <td bgcolor="#CCCCCC" class="style3">&nbsp;Capture Mode&nbsp;</td>
    <td bgcolor="#CCCCCC" class="style3">&nbsp;Communications&nbsp;</td>
    <td bgcolor="#CCCCCC" class="style3">&nbsp;Gateway&nbsp;</td>
  </tr>
  <?php do { ?>
    <tr>
      <td><div align="center"><a href="results2.php?recordID=<?php echo $row_TerminalList['uid']; ?>" class="style3"> <?php echo $row_TerminalList['uid']; ?>&nbsp; </a> </div></td>
      <td class="style3"><?php echo $row_TerminalList['ttDynmcDesc']; ?>&nbsp; </td>
      <td class="style3"><?php echo $row_TerminalList['ttDevType']; ?>&nbsp; </td>
      <td class="style3"><?php echo $row_TerminalList['ttDevMod']; ?>&nbsp; </td>
      <td class="style3"><?php echo $row_TerminalList['ttDevAppType']; ?>&nbsp; </td>
      <td class="style3">
      <?php 
              
if ($row_TerminalList['ttDialUp'] == "Y") {
                echo 
"YES";
                } elseif (
$row_TerminalList['ttDialUp'] == "N") {
                    echo 
"NO";
                    } 
                    
?>&nbsp; </td>
      <td class="style3">
      <?php 
              
if ($row_TerminalList['ttCaptMode'] == "T") {
                echo 
"TERMINAL";
                } elseif (
$row_TerminalList['ttCaptMode'] == "H") {
                    echo 
"HOST"
                    }
                    
?>&nbsp; </td>
      <td class="style3"><?php echo $row_TerminalList['ttDevCommFmt']; ?>&nbsp; </td>
      <td class="style3"><?php echo $row_TerminalList['ttGateWay']; ?>&nbsp; </td>
    </tr>
    <?php } while ($row_TerminalList mysql_fetch_assoc($TerminalList)); ?>
</table>
<br />
<table border="0">
  <tr>
    <td class="style3"><?php if ($pageNum_TerminalList 0) { // Show if not first page ?>
          <a href="<?php printf("%s?pageNum_TerminalList=%d%s"$currentPage0$queryString_TerminalList); ?>">First</a>
          <?php // Show if not first page ?>    </td>
    <td class="style3"><?php if ($pageNum_TerminalList 0) { // Show if not first page ?>
          <a href="<?php printf("%s?pageNum_TerminalList=%d%s"$currentPagemax(0$pageNum_TerminalList 1), $queryString_TerminalList); ?>">Previous</a>
          <?php // Show if not first page ?>    </td>
    <td class="style3"><?php if ($pageNum_TerminalList $totalPages_TerminalList) { // Show if not last page ?>
          <a href="<?php printf("%s?pageNum_TerminalList=%d%s"$currentPagemin($totalPages_TerminalList$pageNum_TerminalList 1), $queryString_TerminalList); ?>">Next</a>
          <?php // Show if not last page ?>    </td>
    <td class="style3"><?php if ($pageNum_TerminalList $totalPages_TerminalList) { // Show if not last page ?>
          <a href="<?php printf("%s?pageNum_TerminalList=%d%s"$currentPage$totalPages_TerminalList$queryString_TerminalList); ?>">Last</a>
          <?php // Show if not last page ?>    </td>
  </tr>
</table>
<span class="style5">Records <?php echo ($startRow_TerminalList 1?> to <?php echo min($startRow_TerminalList $maxRows_TerminalList$totalRows_TerminalList?> of <?php echo $totalRows_TerminalList ?></span>
</body>
</html>
<?php
mysql_free_result
($TerminalList);
?>
Danka
frosty is offline  
Reply With Quote
Old 08-19-2008, 08:46 PM   #2 (permalink)
The Visitor
 
Join Date: Feb 2008
Posts: 4
Thanks: 0
shownomercy is on a distinguished road
Default

This might require a bit of tinkering (and some javascript) but it is a pretty lean way of achieving the striped table look ....
Zebra Striping Made Easy with jQuery
shownomercy is offline  
Reply With Quote
Old 08-19-2008, 09:04 PM   #3 (permalink)
The Wanderer
 
frosty's Avatar
 
Join Date: Aug 2008
Location: texas
Posts: 13
Thanks: 3
frosty is on a distinguished road
Default

Thanks for the link! I'll take a look at it and see what I can do...

This is out of code that I have taken over with the dismissal of the last web guy. 4000+ pages that I have to go through and figure out why he could never get it to work, make it work, complete the project and roll it out by end of October...yeaaah, its gonna be greaaat.
frosty is offline  
Reply With Quote
Old 08-19-2008, 09:42 PM   #4 (permalink)
The Frequenter
Newcomer 
 
xenon's Avatar
 
Join Date: Dec 2007
Location: Bucharest, Romania
Posts: 438
Thanks: 3
xenon is on a distinguished road
Default

Here's a little start:

PHP Code:
<table border="0" cellpadding="0" cellspacing="0" style="width:100%;">
            <?php $bg '#fff'$x 0?>
            <?php while($x <= 10): ?>
            <?php if($bg == '#fff'$bg '#f0f0f0'; else $bg '#fff'?>
            <tr style="background-color:<?php echo $bg?>;">
                <td>abc</td>
            </tr>
            <?php $x++; endwhile; ?>
        </table>
__________________
I have optimistic thoughts, even though sometimes (if not always) life's a bitch.
xenon is offline  
Reply With Quote
The Following User Says Thank You to xenon For This Useful Post:
frosty (08-19-2008)
Old 08-19-2008, 09:51 PM   #5 (permalink)
The Wanderer
 
frosty's Avatar
 
Join Date: Aug 2008
Location: texas
Posts: 13
Thanks: 3
frosty is on a distinguished road
Default

Thanks xenon!

Will give this a try this evening...
frosty is offline  
Reply With Quote
Old 08-19-2008, 11:48 PM   #6 (permalink)
The Wanderer
 
tripy's Avatar
 
Join Date: Apr 2008
Posts: 7
Thanks: 0
tripy is on a distinguished road
Default

Maybe even a bit shorter, from Xenon example:
PHP Code:
<style type="text/css">
.odd{background-color: green;}
.even{background-color: blue;}
</style>
<table border="0" cellpadding="0" cellspacing="0" style="width:100%;">
  <?php
  $bg 
'#fff'$x 0
  while(
$x <= 10){
    
$class=($x%2!==0)?'even':'odd';
    
?>
  <tr class="<? echo $class;?>">
      <td>abc</td>
  </tr>
    <?php 
    $x
++;
  }
  
?>
</table>
tripy is offline  
Reply With Quote
The Following User Says Thank You to tripy For This Useful Post:
frosty (08-28-2008)
Old 08-28-2008, 10:58 PM   #7 (permalink)
The Wanderer
 
frosty's Avatar
 
Join Date: Aug 2008
Location: texas
Posts: 13
Thanks: 3
frosty is on a distinguished road
Default

Thanks for all the input, tried both and both worked well...

Now how do I close this thread...
frosty is offline  
Reply With Quote
Reply



Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


All times are GMT. The time now is 12:25 PM.

 
     

Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.1.0
Inactive Reminders By Icora Web Design