adambedford Posted February 12, 2010 Author Share Posted February 12, 2010 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 Quote Link to comment https://forums.phpfreaks.com/topic/191790-setting-css-class-using-php/page/2/#findComment-1011116 Share on other sites More sharing options...
xjake88x Posted February 12, 2010 Share Posted February 12, 2010 Did you try doing what sader just said? Your query isn't selecting all (*) or selecting the "highlight" row. Quote Link to comment https://forums.phpfreaks.com/topic/191790-setting-css-class-using-php/page/2/#findComment-1011118 Share on other sites More sharing options...
adambedford Posted February 12, 2010 Author Share Posted February 12, 2010 sader! so simple and yet I doubt I would have ever noticed. Thank you so much! It works perfectly now Quote Link to comment https://forums.phpfreaks.com/topic/191790-setting-css-class-using-php/page/2/#findComment-1011119 Share on other sites More sharing options...
xjake88x Posted February 12, 2010 Share Posted February 12, 2010 You should definitely click "Mark as solved" on this topic! Quote Link to comment https://forums.phpfreaks.com/topic/191790-setting-css-class-using-php/page/2/#findComment-1011120 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.