Jump to content

Setting CSS class using PHP


adambedford

Recommended Posts

This is my whole code:

 

<?php require_once('Connections/links.php'); ?>
<?php
if (!function_exists("GetSQLValueString")) {
function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "") 
{
  if (PHP_VERSION < 6) {
    $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"];

$colname_websites = "-1";
if (isset($_GET['Category_ID'])) {
  $colname_websites = $_GET['Category_ID'];
}
mysql_select_db($database_links, $links);
$query_websites = sprintf("SELECT * FROM links WHERE Category_ID = %s AND Visible = 'Y'", GetSQLValueString($colname_websites, "int"));
$websites = mysql_query($query_websites, $links) or die(mysql_error());
$row_websites = mysql_fetch_assoc($websites);
$totalRows_websites = mysql_num_rows($websites);

$maxRows_websites = 20;
$pageNum_websites = 0;
if (isset($_GET['pageNum_websites'])) {
  $pageNum_websites = $_GET['pageNum_websites'];
}
$startRow_websites = $pageNum_websites * $maxRows_websites;

$colname_websites = "-1";
if (isset($_GET['Category_ID'])) {
  $colname_websites = $_GET['Category_ID'];
}
mysql_select_db($database_links, $links);
$query_websites = sprintf("SELECT Name, URL, `Description`, Category_ID FROM links WHERE Category_ID = %s AND Visible = 'Y'", GetSQLValueString($colname_websites, "int"));
$query_limit_websites = sprintf("%s LIMIT %d, %d", $query_websites, $startRow_websites, $maxRows_websites);

$websites = mysql_query($query_limit_websites, $links) or die(mysql_error());
$row_websites = mysql_fetch_assoc($websites);

if (isset($_GET['totalRows_websites'])) {
  $totalRows_websites = $_GET['totalRows_websites'];
} else {
  $all_websites = mysql_query($query_websites);
  $totalRows_websites = mysql_num_rows($all_websites);
}
$totalPages_websites = ceil($totalRows_websites/$maxRows_websites)-1;

$queryString_websites = "";
if (!empty($_SERVER['QUERY_STRING'])) {
  $params = explode("&", $_SERVER['QUERY_STRING']);
  $newParams = array();
  foreach ($params as $param) {
    if (stristr($param, "pageNum_websites") == false && 
        stristr($param, "totalRows_websites") == false) {
      array_push($newParams, $param);
    }
  }
  if (count($newParams) != 0) {
    $queryString_websites = "&" . htmlentities(implode("&", $newParams));
  }
}
$queryString_websites = sprintf("&totalRows_websites=%d%s", $totalRows_websites, $queryString_websites);
?>
<!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=utf-8" />
<title>Untitled Document</title>
<link href="styles/global.css" rel="stylesheet" type="text/css" />
<script type="text/javascript" src="scripts/menu.js"></script>

<link href="styles/links.css" rel="stylesheet" type="text/css" />

</head>

<body>

<div id="wrapper">

<div id="bodywrapper">
  <?php if ($totalRows_websites > 0) { // Show if recordset not empty ?>
  <div id="listings">
    <ul>
      <?php do { ?>
        <?php $class = ($row_websites['Highlight'] == "Y")? "highlighted" : "standard" ?>
        <li class="<?php $class ?>"> <a href="forward.php?URL=<?php echo $row_websites['URL']; ?>"><?php echo $row_websites['Name']; ?></a><?php echo $row_websites['Highlight'] ?></li>
        <?php } while ($row_websites = mysql_fetch_assoc($websites)); ?>
    </ul>
  </div>
  <?php } // Show if recordset not empty 
  
  else { 
  		echo("There are no websites in this category. List yours now for $1!") ;
  }
  ?>
  
</div>  
  <?php print_r($row_websites) ?>
  
<div id="nav"> Websites <?php echo ($startRow_websites + 1) ?> to <?php echo min($startRow_websites + $maxRows_websites, $totalRows_websites) ?> of <?php echo $totalRows_websites ?>
    <table border="0">
      <tr>
        <td><?php if ($pageNum_websites > 0) { // Show if not first page ?>
            <a href="<?php printf("%s?pageNum_websites=%d%s", $currentPage, 0, $queryString_websites); ?>">First</a>
            <?php } // Show if not first page ?></td>
        <td><?php if ($pageNum_websites > 0) { // Show if not first page ?>
            <a href="<?php printf("%s?pageNum_websites=%d%s", $currentPage, max(0, $pageNum_websites - 1), $queryString_websites); ?>">Previous</a>
            <?php } // Show if not first page ?></td>
        <td><?php if ($pageNum_websites < $totalPages_websites) { // Show if not last page ?>
            <a href="<?php printf("%s?pageNum_websites=%d%s", $currentPage, min($totalPages_websites, $pageNum_websites + 1), $queryString_websites); ?>">Next</a>
            <?php } // Show if not last page ?></td>
        <td><?php if ($pageNum_websites < $totalPages_websites) { // Show if not last page ?>
            <a href="<?php printf("%s?pageNum_websites=%d%s", $currentPage, $totalPages_websites, $queryString_websites); ?>">Last</a>
            <?php } // Show if not last page ?></td>
      </tr>
    </table>
  </div>
  
</div>

</body>

</html>

<?php
mysql_free_result($websites);
?>

 

Posting it here I've noticed it looks like I've got some duplicated code...not sure why :S

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.