Jump to content

conditional display


stolea

Recommended Posts

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 of
1 x category "Collars and Armbands"

whic has
2 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 :)
 

Link to comment
Share on other sites

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>';
    }
Link to comment
Share on other sites

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 ||
Link to comment
Share on other sites

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 by paddyfields
Link to comment
Share on other sites

Ah.. thanks. Learnt a few more things  :happy-04:

 

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  {

Link to comment
Share on other sites

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 by paddyfields
Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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.