SitePoint Sponsor

User Tag List

Page 2 of 2 FirstFirst 12
Results 26 to 28 of 28
  1. #26
    Community Advisor silver trophybronze trophy
    dresden_phoenix's Avatar
    Join Date
    Jun 2008
    Location
    Madison, WI
    Posts
    2,802
    Mentioned
    34 Post(s)
    Tagged
    2 Thread(s)
    Why should I replace my div = id with a div = class ??
    IDs cant be repeated.. is just bad mojo. Not just for CSS but for any Javascript you may have running. So if you need to have the same ID then its a class. otherwise make the IDs unique to the page each time they are output...

    You can use PHP to add styling by echoing class="whatever" to whatever you need to style. It can even be in addition to the IDs you have AND you could .. if you so wished to streamline your code ... make the the added class name a variable... echo"class='$whatever' "; that way it could even be in a separate function....

    but what I was trying to say in my earlier post .. is that the styling is not done by PHP... it is done by CSS.. so the key here is to use PHP to target where you want a css style applied ... ( whether the nav is constructed in one or 3 places doesnt matter then) you can ADD the rules you need by adding a class to the element along the ID... <div id="navbar2" class="whatever"> and add .whatever{your:rules...} to your CSS style sheet.

    Either way, you still should only use the IDs once in the name space.

  2. #27
    Non-Member bronze trophy
    Join Date
    Nov 2009
    Location
    Keene, NH
    Posts
    3,760
    Mentioned
    23 Post(s)
    Tagged
    0 Thread(s)
    For the most part people are pointing you the right way on the html/css side, your PHP and mySQL makes me shudder a wee bit.

    Some advice:

    Don't use string additions (periods) inside echo's unless it's actually a string addition (like inside a conditional) -- they take longer than comma's. Don't use double quotes on echos unless you are using escape characters or inlined-strings, they take longer and make it harder to output 'normal looking' HTML.

    I mean just this:
    Code:
     	echo "<a href='categorylist.php?category=".$row['name']."'>".$row['name']."</a>";
    Is a mix of two coding styles... pick one, not both. That could be either:

    Code:
     	echo '<a href="categorylist.php?category=',$row['name'],'">",$row['name'],'</a>';
    or

    Code:
     	echo "<a href='categorylist.php?category=$row[name]'>$row[name]</a>";
    See the difference? The first allows for whitespace character retention and generally executes a hair faster (so small most coders don't really mention it anymore), the latter means no whitespace for formatting is available, but many people find simpler. (the lack of delimiters make it more confusing to me, but I've never been a fan of the C printf function except for dynamic string use).

    ... and don't EVER send a $_GET directly into a query string... though that's why the mysql_ functions NEED to go the way of the dodo in favor or MYSQLI or PDO.

    Though with the other responses I'm stuck asking what's with the extra DIV since UL's a perfectly good block level container... and if you use single quotes as I outlined above, your output could retain formatting making it easier to debug.

  3. #28
    Non-Member bronze trophy
    Join Date
    Nov 2009
    Location
    Keene, NH
    Posts
    3,760
    Mentioned
    23 Post(s)
    Tagged
    0 Thread(s)
    Just to give an idea what I'm talking about -- IF I understood the what you wanted to have for logic flow on that last post of your code:

    Code:
    echo '
    	<div id="leftCol">';
    
    if (isset($selcat3)) {
    
    	$result=mysql_query('
    		SELECT subcategory2id,name
    		FROM products
    		WHERE reference='.$selcat3
    	);
    
    	echo '
    
    		<ul class="selCat">';
    
    	while ($row=mysql_fetch_array($result)) echo '
    			<li>
    				<a href="subcategory1id.php?subcategory1=',$row['subcategory2id'],'">
    					',$row['name'],'
    				</a>
    			</li>';
    
    	echo '
    		</ul>
    
    		<ul class="getSubCat2">';
    
    
    	$result=mysql_query('
    		SELECT subcategory2id,name
    		FROM products
    		WHERE subcategoryid = '.$_GET['subcategory2']
    	);
    
    	while ($row=mysql_fetch_array($result)) echo '
    			<li>
    				<a href="categorylist.php?category=',$row['subcategory2id'],'">
    					',$row['name'],'
    				</a>
    			</li>';
    
    	echo '
    		</ul>';
    
    	unset($cats[$selcat3]); //Gets rid of it for later.
    }
    
    
    echo '
    		<ul class="cats">';
    
    foreach($cats AS $key => $cat) {
    	echo '
    			<li><a href="categoryview.php?category=',$key,'">',$cat,'</a></li>';
    }
    
    echo '
    		</ul>
    
    	<!-- #leftCol --></div>';
    Is about how I'd be coding that... give or take.

    You'll notice I gave them classes so they can be targeted as unique -- if they are all getting the same class, they probably do NOT need a class and should be targeted off the parent... likewise UL is a perfectly good block level container, so there should be no reason for the extra DIV around each.


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •