Jump to content

[SOLVED] bolding certain links from database?


sandbudd

Recommended Posts

How would I go about to bold certain links from a list in a mysql database?

 

<?
require_once('includes/config.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";
		}

		$page['content'] .= "<li><a href=\"brand.php?bID=$bId\">$bName</a></li>\n";
	}

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

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

print_page();
?>

Well, if this information is coming from a database, I would add and extra field called bold or something and set it to 0 or 1 for fields that need to be bolded.  That would be the best way.

 

If not, you could do something like:

<?php
$bolded_ids=array(95, 23, 102);  //your ids....
//then in your loop where you want it to be bolded
if(in_array($id, $bolded_ids)) {
    $link="<strong>" . $text . "</strong>";
} else {
    $link = $text;
}

I didn't use your variable names, but I think you can see whats going on.

You would put the $bolded_ids=array(23,434,24); just ABOVE your very first if statement

<?php 
$bolded_ids=array(23,434,24);
if(count($brands)>0)
// ...

then replace the line you provided with this:

<?php
//line to remove
$page['content'] .= "<li><a href=\"brand.php?bID=$bId\">$bName</a></li>\n";
//replace with
$bold_value = in_array($bId, $bolded_ids) ? "<strong>$bName</strong>" : $bName;
$page['content'] .= "<li><a href=\"brand.php?bID=$bId\">$bold_value</a></li>\n";

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.