sandbudd Posted October 8, 2008 Share Posted October 8, 2008 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(); ?> Quote Link to comment Share on other sites More sharing options...
CroNiX Posted October 8, 2008 Share Posted October 8, 2008 You can either add a class to the anchor and then use css to style that class, or use <strong></strong> tags instead of the <h3> tags. Quote Link to comment Share on other sites More sharing options...
sandbudd Posted October 8, 2008 Author Share Posted October 8, 2008 I am only wanting certain fields in the table to be bolded? Quote Link to comment Share on other sites More sharing options...
sandbudd Posted October 8, 2008 Author Share Posted October 8, 2008 say for example id 95 Quote Link to comment Share on other sites More sharing options...
CroNiX Posted October 8, 2008 Share Posted October 8, 2008 First you said links, now you say fields. Which is it and if its fields, define what that means please. <strong>my text</strong> will be bolded. Quote Link to comment Share on other sites More sharing options...
CroNiX Posted October 8, 2008 Share Posted October 8, 2008 How do you know which IDs need to be bolded? Is there a way to figure that out programatically or is it just something that YOU know? Quote Link to comment Share on other sites More sharing options...
sandbudd Posted October 8, 2008 Author Share Posted October 8, 2008 I know which ID's need to be bolded Quote Link to comment Share on other sites More sharing options...
CroNiX Posted October 8, 2008 Share Posted October 8, 2008 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. Quote Link to comment Share on other sites More sharing options...
sandbudd Posted October 8, 2008 Author Share Posted October 8, 2008 where would I put that in the current php...This is the line that pulls it from the database. Sorry to be asking so many question. } $page['content'] .= "<li><a href=\"brand.php?bID=$bId\">$bName</a></li>\n"; } Quote Link to comment Share on other sites More sharing options...
CroNiX Posted October 8, 2008 Share Posted October 8, 2008 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"; Quote Link to comment Share on other sites More sharing options...
sandbudd Posted October 8, 2008 Author Share Posted October 8, 2008 worked like a charm...tx Quote Link to comment Share on other sites More sharing options...
CroNiX Posted October 8, 2008 Share Posted October 8, 2008 NP Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.