Jump to content

pulling from database change color


sandbudd

Recommended Posts

I am trying to make certain links pulled from the database to turn a different color.  Here is an example that works for one page and I cant get it to work for another.

 

<?
require_once('includes/init.php');



$page['products'] = $catalog->getCategories();

$brands = $catalog->getBrandList();

$page['content'] = "<h2>Brands</h2>\n<div class=\"mainContent\">";
if(count($brands)>0)
{
	$curSection=ord('A')-1;
	foreach($brands as $bId => $bName)
	{
		while($curSection < ord($bName[0]))
		{
			if($curSection++>=ord('A')) $page['content'] .= "\n</ul>\n";

			$page['content'] .= "<a name=\"" . chr($curSection) . "\">";

			if(chr($curSection)==$bName[0]) $page['content'] .= "<h3>".$bName[0]."</h3>";
			$page['content'] .= "</a>\n<ul>\n";
		}

		$bold_value = in_array($bId, $bolded_ids) ? "<font color=red>$bName (TOP 20)</font>" : $bName;
$page['content'] .= "<li><a href=\"brand.php?bID=$bId\">$bold_value</a></li>\n";
	}

	$page['content'] .= "</ul>\n";

	while($curSection < ord('Z'))
		$page['content'] .= "<a name=\"" . chr(++$curSection) . "\"></a>\n";
}
$page['content'] .= "</div>";

print_page();
?>

 

in the require_once('includes/init.php'); I have a call to bold.php Here is that file

 

<?
$bolded_ids=array(24,92,93,84,28,48,2,74,31,64);
if(count($brands)>0)
?>

 

Here is the file that is not working and I do not know why?

 

<?
require_once('includes/init.php');
require_once ('includes/bold.php');

$page['products'] = $catalog->getCategories();
$category = $catalog->getCategoryInfo($core->pageVar('catID', siteCore::VARTYPE_INT));

$page['content'] = "<h2>".$category['CategoryName']."</h2>\n<div class=\"mainContent\">\n";
if(count($category['Subcats'])>0)
{
	$page['content'] .= "<ul>\n";
	foreach($category['Subcats'] as $subcatID => $subcatName)


		$bold_value = in_array($subcatID, $bolded_ids) ? "<font color=red>$subcatName</font>" : $subcatName;
$page['content'] .= "<li><a href=\"subcategory.php?sCatID=$subcatID\">$bold_value</a></li>\n";

	$page['content'] .= "</ul>\n";
}
$page['content'] .= "</div>";

print_page();
?>
[/code

Link to comment
Share on other sites

Hello again, I recognize that code  ;D

 

Font tags should not be used because they have been deprecated a long time ago.  See http://www.w3.org/TR/html401/present/graphics.html section 15.2.2.  Try using a span with a class name and use css.  Its best to put the stylesheet in its own file.  Also, it is a good idea to avoid color names like 'red'.  Actually define them, #FF0000.  Different browsers interpret color names differently.

<head>

<style ="text/css">

.redFont { color:#FF0000; }

</style>

</head>

...

<span class="redFont">$subcatName</span>

Link to comment
Share on other sites

get this

 

Array

(

    [subcats] => Array

        (

            [124] => Diet Bars

            [123] => Energy Bar

            [125] => Meal Replacement Bars

            [122] => Protein Bars

        )

 

    [CategoryName] => Protein Bars/Meal Replacement Bars

)

 

Link to comment
Share on other sites

this is the line that displayed the data and did display

 

$page['content'] .= "<li><a href=\"subcategory.php?sCatID=$subcatID\">$subcatName</a></li>\n";

 

I changed to this

 

$bold_value = in_array($subcatID, $bolded_ids) ? "<strong>$subcatName (TOP 20)</strong>" : $subcatName;

$page['content'] .= "<li><a href=\"subcategory.php?sCatID=$subcatID\">$bold_value</a></li>\n";

Link to comment
Share on other sites

Hi CroNIX here it is

 

bold.php

 


<?php
$bolded_ids=array(24,92,93,84,28,48,2,74,31,64,122,123,124);
if(count($brands)>0)
?>

 

 


<?php
require_once('includes/init.php');
require_once ('includes/bold.php');

$page['products'] = $catalog->getCategories();
$category = $catalog->getCategoryInfo($core->pageVar('catID', siteCore::VARTYPE_INT));


$page['content'] = "<h2>".$category['CategoryName']."</h2>\n<div class=\"mainContent\">\n";
if(count($category['Subcats'])>0)
{
	$page['content'] .= "<ul>\n";
	foreach($category['Subcats'] as $subcatID => $subcatName)


		$bold_value = in_array($subcatID, $bolded_ids) ? "<strong>$subcatName (TOP 20)</strong>" : $subcatName;
$page['content'] .= "<li><a href=\"subcategory.php?sCatID=$subcatID\">$bold_value</a></li>\n";

	$page['content'] .= "</ul>\n";
}
$page['content'] .= "</div>";

print_page();
?>

Link to comment
Share on other sites

<?php
foreach($category['Subcats'] as $subcatID => $subcatName){        
    $bold_value = in_array($subcatID, $bolded_ids) ? "<strong>$subcatName (TOP 20)</strong>" : $subcatName;
    $page['content'] .= "<li><a href=\"subcategory.php?sCatID=$subcatID\">$bold_value</a></li>\n";

    $page['content'] .= "</ul>\n";
}

Link to comment
Share on other sites

changed to this and get a blank page?

 

<?php
require_once('includes/init.php');

$page['products'] = $catalog->getCategories();
$category = $catalog->getCategoryInfo($core->pageVar('catID', siteCore::VARTYPE_INT));


$page['content'] = "<h2>".$category['CategoryName']."</h2>\n<div class=\"mainContent\">\n";
if(count($category['Subcats'])>0)
{
	$page['content'] .= "<ul>\n";
	foreach($category['Subcats'] as $subcatID => $subcatName){        
    $bold_value = in_array($subcatID, $bolded_ids) ? "<strong>$subcatName (TOP 20)</strong>" : $subcatName;
    $page['content'] .= "<li><a href=\"subcategory.php?sCatID=$subcatID\">$bold_value</a></li>\n";

    
}
$page['content'] .= "</ul>\n";
$page['content'] .= "</div>";

print_page();
?>

Link to comment
Share on other sites

still blank page... Doesnt make any sense considering it works great on the other page.

 

<?php
require_once('includes/init.php');

$page['products'] = $catalog->getCategories();
$category = $catalog->getCategoryInfo($core->pageVar('catID', siteCore::VARTYPE_INT));


$page['content'] = "<h2>".$category['CategoryName']."</h2>\n<div class=\"mainContent\">\n";
if(count($category['Subcats'])>0)
{
	$page['content'] .= "<ul>\n";
	foreach($category['Subcats'] as $subcatID => $subcatName){        
    $bold_value = in_array($subcatID, $bolded_ids) ? "<strong>$subcatName (TOP 20)</strong>" : $subcatName;
    $page['content'] .= "<li><a href=\"subcategory.php?sCatID=$subcatID\">$bold_value</a></li>\n";

    
}
$page['content'] .= "</ul>\n";
$page['content'] .= "</div>";

echo $page['content'];
print_page();
?>

Link to comment
Share on other sites

still blank page?

 


<?php
require_once('includes/init.php');

$page['products'] = $catalog->getCategories();
$category = $catalog->getCategoryInfo($core->pageVar('catID', siteCore::VARTYPE_INT));


$page['content'] = "<h2>".$category['CategoryName']."</h2>\n<div class=\"mainContent\">\n";
if(count($category['Subcats'])>0)
{
	$page['content'] .= "<ul>\n";
	foreach($category['Subcats'] as $subcatID => $subcatName){        
    $bold_value = in_array($subcatID, $bolded_ids) ? "<strong>$subcatName (TOP 20)</strong>" : $subcatName;
    $page['content'] .= "<li><a href=\"subcategory.php?sCatID=$subcatID\">$bold_value</a></li>\n";

    
}
$page['content'] .= "</ul>\n";
$page['content'] .= "</div>";

echo "<pre>"; print_r($page); echo "</pre>";
print_page();
?>

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.