TalkPHP

TalkPHP (http://www.talkphp.com/forums.php)
-   General (http://www.talkphp.com/general/)
-   -   Ok, my first real issue!! (http://www.talkphp.com/general/3262-ok-my-first-real-issue.html)

frosty 08-19-2008 08:00 PM

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

shownomercy 08-19-2008 08:46 PM

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

frosty 08-19-2008 09:04 PM

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.:-/

xenon 08-19-2008 09:42 PM

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>


frosty 08-19-2008 09:51 PM

Thanks xenon!

Will give this a try this evening...

tripy 08-19-2008 11:48 PM

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>


frosty 08-28-2008 10:58 PM

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

Now how do I close this thread...


All times are GMT. The time now is 06:11 AM.

Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.1.0