sandbudd Posted October 9, 2008 Share Posted October 9, 2008 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 Quote Link to comment Share on other sites More sharing options...
CroNiX Posted October 9, 2008 Share Posted October 9, 2008 Hello again, I recognize that code 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> Quote Link to comment Share on other sites More sharing options...
sandbudd Posted October 9, 2008 Author Share Posted October 9, 2008 Hi CroNIX thanks for your help yesterday. The first code works fine and I will put the color in the css but it is the same code you helped me with yesterday and I don't know why it isn't working here? Quote Link to comment Share on other sites More sharing options...
sandbudd Posted October 9, 2008 Author Share Posted October 9, 2008 The problem isnt in the color...When I put the code in I dont get any display from the database Quote Link to comment Share on other sites More sharing options...
CroNiX Posted October 9, 2008 Share Posted October 9, 2008 Immediately after this line: <?php $category = $catalog->getCategoryInfo($core->pageVar('catID', siteCore::VARTYPE_INT)); Add: <?php echo "<pre>"; print_r($category); echo "</pre>"; what does it show? Quote Link to comment Share on other sites More sharing options...
sandbudd Posted October 9, 2008 Author Share Posted October 9, 2008 get this Array ( [subcats] => Array ( [124] => Diet Bars [123] => Energy Bar [125] => Meal Replacement Bars [122] => Protein Bars ) [CategoryName] => Protein Bars/Meal Replacement Bars ) Quote Link to comment Share on other sites More sharing options...
sandbudd Posted October 9, 2008 Author Share Posted October 9, 2008 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"; Quote Link to comment Share on other sites More sharing options...
sandbudd Posted October 9, 2008 Author Share Posted October 9, 2008 changed color to strong Quote Link to comment Share on other sites More sharing options...
CroNiX Posted October 9, 2008 Share Posted October 9, 2008 well, your original $bolded_ids array does not contain 122, 123, 124 or 125, so they would not get affected... Quote Link to comment Share on other sites More sharing options...
sandbudd Posted October 9, 2008 Author Share Posted October 9, 2008 sorry CroNIX I had added them after post and still dont get nothing Quote Link to comment Share on other sites More sharing options...
CroNiX Posted October 9, 2008 Share Posted October 9, 2008 OK, Im on my way out for a meeting with a client. Ill try to look later if you haven't figured it out. Quote Link to comment Share on other sites More sharing options...
sandbudd Posted October 9, 2008 Author Share Posted October 9, 2008 Thank you Quote Link to comment Share on other sites More sharing options...
sandbudd Posted October 10, 2008 Author Share Posted October 10, 2008 friendly bump...does anyone have a suggestion? Quote Link to comment Share on other sites More sharing options...
CroNiX Posted October 10, 2008 Share Posted October 10, 2008 Please repost your code with all of your changes. Use the code tags and start with <?php so it will format/highlight the code. Quote Link to comment Share on other sites More sharing options...
sandbudd Posted October 10, 2008 Author Share Posted October 10, 2008 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(); ?> Quote Link to comment Share on other sites More sharing options...
CroNiX Posted October 10, 2008 Share Posted October 10, 2008 You don't have curly braces {} around your foreach statement: foreach(blah as blah){ ... ... } Quote Link to comment Share on other sites More sharing options...
CroNiX Posted October 10, 2008 Share Posted October 10, 2008 and what does your print_page() function look like? Quote Link to comment Share on other sites More sharing options...
sandbudd Posted October 10, 2008 Author Share Posted October 10, 2008 where exactly do I put the curly brackets? Quote Link to comment Share on other sites More sharing options...
CroNiX Posted October 10, 2008 Share Posted October 10, 2008 <?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"; } Quote Link to comment Share on other sites More sharing options...
CroNiX Posted October 10, 2008 Share Posted October 10, 2008 oops, I don't think that last line should be in the braces. It should be just below the closing brace. Quote Link to comment Share on other sites More sharing options...
sandbudd Posted October 10, 2008 Author Share Posted October 10, 2008 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(); ?> Quote Link to comment Share on other sites More sharing options...
CroNiX Posted October 10, 2008 Share Posted October 10, 2008 add: echo $page['content']; just above your print_page() function. Quote Link to comment Share on other sites More sharing options...
sandbudd Posted October 10, 2008 Author Share Posted October 10, 2008 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(); ?> Quote Link to comment Share on other sites More sharing options...
CroNiX Posted October 10, 2008 Share Posted October 10, 2008 replace echo $page['content']; with echo "<pre>"; print_r($page); echo "</pre>"; and post the output. Quote Link to comment Share on other sites More sharing options...
sandbudd Posted October 10, 2008 Author Share Posted October 10, 2008 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(); ?> 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.