CSS and PHP Problem

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
mmc01ms
Forum Commoner
Posts: 97
Joined: Wed Dec 01, 2004 3:33 am
Location: Nottingham, UK

CSS and PHP Problem

Post by mmc01ms »

Hi guys im trying to get a piece of code to work which involves setting the background colour of a <div> using CSS. The colour of the background is dependent on what department a job is advertised for. For example if it is the personal department then the background needs to be green etc while a business department advert would be purple. I'm using the department id to assign the colour value using php. The problem is the first item in the database has a department id of 1 and thereforethe background colour will be set to purple. The second item has a department id of 2 therefore the colour value should be set to green however it sets the background colour the same as before. I've included the code and the html page im testing on is:

Can anyone help?

http://www.ashtonmortonslack.co.uk/recr ... urrent.php

the code is as followed

Code: Select all

<?php
mysql_select_db($database_dbConn, $dbConn);
$query_currentVacancies = "SELECT * FROM ams_recruitment WHERE visible = 'Y'AND closing_date >= CURDATE() ORDER BY closing_date DESC";
$currentVacancies = mysql_query($query_currentVacancies, $dbConn) or die(mysql_error());
$row_currentVacancies = mysql_fetch_assoc($currentVacancies);
$totalRows_currentVacancies = mysql_num_rows($currentVacancies);
		
		
		
?><!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" lang="en"><!-- InstanceBegin template="/Templates/recruitment.dwt.php" codeOutsideHTMLIsLocked="false" -->
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<!-- InstanceBeginEditable name="doctitle" -->
<title>Ashton Morton Slack: Current vacancies</title>
<!-- InstanceEndEditable -->
<!-- The following stylesheet import only works for IE5+ and NS6+, earlier browser get text only -->
<style type="text/css" >
<!--
@import url(../css/ams_common.css);
@import url(../css/ams_generic.css);

.jobVacancy {
	margin: 15px 0;
	background-color: #<?php 	
		if($row_currentVacancies['category'] == 1)
		echo("4A207e");
		else if ($row_currentVacancies['category'] == 2)
		echo("A22630");
		else if($row_currentVacancies['category'] == 3)
		echo("13694e");
		else if($row_currentVacancies['category'] == 4)
		echo("00436e"); 
	    ?>;
	padding: 5px 0;
}
-->
</style>
<script language="JavaScript" type="text/JavaScript">
<!--
function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}
//-->
</script>
<!-- InstanceBeginEditable name="head" --><!-- InstanceEndEditable -->
</head>

<body onload="MM_preloadImages('../Templates/%3C%3Fphp%20echo%20$image_path;%20?%3E/links_over.gif','../Templates/%3C%3Fphp%20echo%20$image_path;%20?%3E/search_over.gif','../Templates/%3C%3Fphp%20echo%20$image_path;%20?%3E/home_over.gif','../Templates/%3C%3Fphp%20echo%20$image_path;%20?%3E/contact_over.gif')">

<div class="hideFromCSSBrowsers"><p><a href="#mainContent">Jump to main content</a>. </p><p><strong>You are viewing this site with Style Sheets turned off, or a browser which is not CSS standards compliant. You can still use a basic version of the site. You may wish to consider upgrading to a compatible, such as recent versions of <a href="http://www.microsoft.com/windows/ie/default.mspx" target="_blank">Microsoft Internet Explorer</a> or <a href="http://www.mozilla.org/products/firefox/" target="_blank">Firefox</a>.</strong></p></div>

<div id="headerContainer">
<div id="mainLogo"><a href="/"><img src="../images/!generic/main_logo.gif" alt="ashton morton slack"  width="305" height="54" border="0" title="ashton morton slack" /></a></div>

	<div id="siteTools">
		<?php $image_path = '/images/!generic/site_tool_icons'; ?>
		<?php include('../includes/nav_sitetools.php'); ?>
	</div>

    <ul id="globalNav">
		<?php include('../includes/nav_globalnav.php'); ?>
	</ul>
	
	<div id="headerImageBoxes">
		<a href="/business"><img src="../images/!generic/header_box1.gif" alt="Business Services" title="Business Services"  width="58" height="58" border="0" /></a>
		<a href="/personal-injury"><img src="../images/!generic/header_box2.gif" alt="Personal Injury" title="Personal Injury" width="58" height="58" border="0" /></a>
		<a href="/private-client"><img src="../images/!generic/header_box3.gif" alt="Private Client" title="Private Client"  width="58" height="58" border="0" /></a>
	</div>
	
</div>

<<div id="contentContainer">

	<div id="breakingNewsContainer" class="roundedBox">
		<div class="roundedBoxTop">&nbsp;</div>
		<div class="roundedBoxImage"><img src="../images/left_box_photos/people.jpg" alt="People" width="151" height="90" /></div>
		  <!-- InstanceBeginEditable name="subnav" -->
		  <h2  class="subnavSelected"><a href="index.php">Recruitment home </a></h2>
		  <h2><a href="current.php">Current vacancies</a></h2>
		  <h2><a href="apply.php">Making an application</a></h2>
		  <h2><a href="work-exp.php">Work experience</a></h2>
		  <h2><a href="benefits.php">Benefits</a></h2>
		  <h2><a href="equal-opps.php">Equal opportunities</a></h2>
		  <h2><a href="case-studies.php">Case studies</a></h2>
		  
		  <!-- InstanceEndEditable -->
		  <div class="roundedBoxBottom">&nbsp;</div>
		<div class="clear"></div>
	</div>
	
	
	<div id="mainContent">
        <!-- InstanceBeginEditable name="maincontent" -->
        <h1>Current vacancies </h1>
        <p>Recruitment drives are held every quarter January, April, July and October.</p>
        <p>Training contract applications are short listed in 31 March of the
           training year and successful applicants are contacted for an interview
          in May. </p>
        <?php if ($totalRows_currentVacancies == 0) { // Show if recordset empty ?>
		<p><strong>We do not currently have any vacancies.</strong></p>
		<?php } // Show if recordset empty ?>
		<?php if ($totalRows_currentVacancies > 0) { // Show if recordset not empty ?>
		<?php do { ?>
		<div class="jobVacancy">
			<h2><?php echo $row_currentVacancies['job_title']; ?></h2>
			<p><?php echo substr(strip_tags($row_currentVacancies['job_description']), 0, 120); ?><?php echo ((strlen($row_currentVacancies['job_description']) > 120)?'...':''); ?> <a href="job_detail.php?job_id=<?php echo $row_currentVacancies['job_id']; ?>">More</a> </p>
		</div>
		<?php } while ($row_currentVacancies = mysql_fetch_assoc($currentVacancies)); ?>
		<?php } // Show if recordset not empty ?>
		
		<p>If you have any queries please contact either:</p>
		<p><strong>Hannah Southern &ndash; HR Manager </strong><br />
		Direct telephone number: 0114 228 9465 <br />
		Email: <a href="mailto:hannah.southern@amslaw.co.uk"> hannah.southern@</a><a href="http://www.ashtonmortonslack.co.uk/">ashtonmortonslack.co.uk</a></p>
		<p> <strong>Lisa Cooke &ndash; HR Assistant </strong><br />
	Direct telephone number: 0114 228 8870 <br />
	Email: <a href="mailto:lisa.cooke@ashtonmortonslack.co.uk"> lisa.cooke@</a><a href="http://www.ashtonmortonslack.co.uk/">ashtonmortonslack.co.uk</a></p>
        <!-- InstanceEndEditable --></div>
	  
	  
      <div class="clear"></div>
	  
</div>
	




<!-- #BeginLibraryItem "/Library/footer.lbi" --><div id="copyright">
Copyright &copy; Ashton Morton Slack 2005
<br />
<a href="../disclaimer/index.php">Disclaimer</a> | <a href="../contact/index.php?sid=21">Suggestions</a>
</a> | <a href="http://www.rocketss.com/">Site by Rocketss </a></div>
<!-- #EndLibraryItem --></body>
<!-- InstanceEnd --></html>
<?php
mysql_free_result($currentVacancies);
?>
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

with the logic you have, only the first record found will determine the colour of the background shown on all of them. Instead, use CSS to actually cascade things: create a universal (for the jobs) css branch containing the fonts and colors that all the jobs share. Next create a class definition for each type of job that adds their "custom" background. During your display loop look at the job type, match it to a class definition and emit the class name.
Post Reply