stolea Posted June 11, 2014 Share Posted June 11, 2014 Hi, I have a website that is 80% done when my programmer dropped the ball. I am trying to get it all to work, but have only rudimentary knowledge on what I am doing thus far and need a bit of help, please. I have a couple of popups links that writes a reminder to check the size of necks and arms at the top of certain pages. One of my product groups is called Collars and Armbands which consists of1 x category "Collars and Armbands" whic has2 x Subcategories which are "Collars" and "Armbands"if I click on the "Collars and Armbands" tab, it displays all the contents of both subcategories Collars and Armbands, as expected. It displays the popup links for both subcategories. I don't want the popups to appear on the "Collars and Armbands" page but only on the individual "Collars" or "Armbands" pages if I click on Collars or Armbands subcategory tabs it displays the single popup link for that category. (which is what I want it to do)The problem lies in the category and subcategory names which I can't really change without making it non-logical for the customer.this the code that makes is happen if ( substr_count($sectionname,'Collars')>0 || substr_count($productname,'Collar')>0 ) { echo '<p class="measurelink noprint">Remember to <a href="neckmeasurepop.php" class="lnkpopup sllink" title="click for popup measuring instructions" onclick="slf_popupwin();return false;">Measure Your Collar Size !</a></p>'; }My question is, is there a way to set a condition that I can use for this code that says "if the $sectionname = "Collars" but NOT "Collars and Armbands" and $productname = "Collar" then display the popup link "neckmeasurepop.php". I had considered renaming the base category to something else, but that would just make things confusing for the customers. Cheers and thanks in advance Quote Link to comment Share on other sites More sharing options...
fastsol Posted June 11, 2014 Share Posted June 11, 2014 Seems like you already know what to do but haven't put in place. Have you tried this if ( $sectionname == 'Collars' && $productname == 'Collar' ) { echo '<p class="measurelink noprint">Remember to <a href="neckmeasurepop.php" class="lnkpopup sllink" title="click for popup measuring instructions" onclick="slf_popupwin();return false;">Measure Your Collar Size !</a></p>'; } Quote Link to comment Share on other sites More sharing options...
stolea Posted June 11, 2014 Author Share Posted June 11, 2014 Thanks fastol, did as suggested but it displays nothing in either base or subcategory (: Quote Link to comment Share on other sites More sharing options...
stolea Posted June 11, 2014 Author Share Posted June 11, 2014 I just tried the following version of your code if ( $sectionname == 'Collars' || $productname == 'Collar' ) { echo '<p class="measurelink noprint">Remember to <a href="neckmeasurepop.php" class="lnkpopup sllink" title="click for popup measuring instructions" onclick="slf_popupwin();return false;">Measure Your Collar Size !</a></p>'; } and that works Silly question: what is the difference between ?? and || Quote Link to comment Share on other sites More sharing options...
paddy_fields Posted June 11, 2014 Share Posted June 11, 2014 (edited) They are logical operators: http://www.php.net//manual/en/language.operators.logical.php && = AND || = OR So I assume that the script isn't working in the way you intend if '&&' is failing. At present your script is only matching either $sectionname or $productname, but not both. Echo what you have in $sectionname and $productname to check Edited June 11, 2014 by paddyfields Quote Link to comment Share on other sites More sharing options...
stolea Posted June 13, 2014 Author Share Posted June 13, 2014 Ah.. thanks. Learnt a few more things I did the echo as suggested and discovered that it is picking up the value of $sectionname == 'Collars', but bombs out on $productname == 'Collar' . the problem is that the product name is something like "38mm collar with spikes" and the $prodname is looking for a product called "Collar" Soooo..... how do I say "look for the word "collar" or "Collar" in a string of words."? I tried if ( $sectionname == 'Belts' || (strpos($productname, 'belt') !== false ) {echo $sectionname, $productname;} but that just gave an error message about an unexpected { Quote Link to comment Share on other sites More sharing options...
paddy_fields Posted June 13, 2014 Share Posted June 13, 2014 (edited) Your syntax is wrong on the if statement, you have an opening bracket before the strpos when it isn't needed; $sectionname = 'Belts'; $productname = 'This is a belt'; if ( $sectionname == 'Belts' && strpos($productname, 'belt') !== false) { echo "Section Name: $sectionname, "; echo "Product Name: $productname"; } P.S Wrap your code when you post using the forum posting tools, it's much easier to read. Edited June 13, 2014 by paddyfields Quote Link to comment Share on other sites More sharing options...
mac_gyver Posted June 13, 2014 Share Posted June 13, 2014 the display strings you have created/defined for categories/subcategories... need to each have a unique id (automatically) assigned to them and be stored in a database table (the database table will also have a 'parent' column that relates subcategories to the corresponding parent category. main categories will have a parent id of zero.) your program logic should only be referencing the id's (this will allow the names to be changed at any time and will actually result in the fastest running code.) then, to add a unique program operation, like a size check reminder pop-up, you would simply test for the id(s) that correspond to that operation. 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.