Jump to content

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";

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.