Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 5 of 5
  1. #1
    New to the CF scene
    Join Date
    Nov 2011
    Posts
    6
    Thanks
    2
    Thanked 0 Times in 0 Posts

    If Certain User Type, then Replace Image/Link Help

    Please help. I'm trying to replace an image & link only when certain "Dealer" users visit my page. If the user is not a Dealer, the default image and link should be shown.

    With my current code, I'm seeing the modified image and link when a Dealer users visits the page, but the problem is that the default image is shown as well (stacked below the Dealer image & link).

    I think my problem is that I'm posting the Dealer image and link instead of "replacing" the default image and link. Here's my code:

    Code:
    if($dealer['user_id'] > 0){
    	print '
    <h3>How It Works</h3>
    <p>Click on each step to learn more</p>
    <p style="text-align:center;"><img alt="" border="0" src="'.D.'uploads/users/images/why-pre-sell-dealer.gif" style="width:465px; height:306px;" usemap="#whatspresell" />
      <map id="whatspresell" name="whatspresell">
        <area alt="" class="colorbox {iframe:true,height:300,width:300}" coords="156,1,300,49" href="'.D.'files/why-pre-sell-popup.php?id=94" shape="rect" />
        <area alt="" class="colorbox {iframe:true,height:625,width:810}" coords="327,77,463,131" href="'.D.'files/why-pre-sell-popup.php?id=95" shape="rect" />
        <area alt="" class="colorbox {iframe:true,height:650,width:800}" coords="295,182,440,237" href="'.D.'files/why-pre-sell-popup.php?id=96" shape="rect" />
        <area alt="" class="colorbox {iframe:true,height:700,width:900}" coords="156,258,303,302" href="'.D.'files/why-pre-sell-popup.php?id=97" shape="rect" />
        <area alt="" class="colorbox {iframe:true,height:400,width:900}" coords="13,179,159,232" href="'.D.'files/why-pre-sell-popup.php?id=98" shape="rect" />
        <area alt="" class="colorbox {iframe:true,height:450,width:550}" coords="1,62,134,119" href="'.D.'files/why-pre-sell-popup.php?id=106" shape="rect" />
      </map>
    </p>
    ';
    }
    print '
    
    <h3>How It Works</h3>
    <p>Click on each step to learn more</p>
    <p style="text-align:center;"><img alt="" border="0" src="'.D.'uploads/users/images/why-pre-sell-2.gif" style="width:465px; height:306px;" usemap="#whatspresell" />
      <map id="whatspresell" name="whatspresell">
        <area alt="" class="colorbox {iframe:true,height:300,width:300}" coords="156,1,300,49" href="'.D.'files/why-pre-sell-popup.php?id=94" shape="rect" />
        <area alt="" class="colorbox {iframe:true,height:625,width:810}" coords="327,77,463,131" href="'.D.'files/why-pre-sell-popup.php?id=95" shape="rect" />
        <area alt="" class="colorbox {iframe:true,height:650,width:800}" coords="295,182,440,237" href="'.D.'files/why-pre-sell-popup.php?id=96" shape="rect" />
        <area alt="" class="colorbox {iframe:true,height:700,width:900}" coords="156,258,303,302" href="'.D.'files/why-pre-sell-popup.php?id=97" shape="rect" />
        <area alt="" class="colorbox {iframe:true,height:400,width:900}" coords="13,179,159,232" href="'.D.'files/why-pre-sell-popup.php?id=98" shape="rect" />
        <area alt="" class="colorbox {iframe:true,height:450,width:550}" coords="1,62,134,119" href="'.D.'files/why-pre-sell-popup.php?id=99" shape="rect" />
      </map>
    </p>
    ';
    ?>
    The only 2 differences between the Dealer and default sections are the src= image and the ID in the 6th "area". Here's a screen shot of my issue:



    If you have questions I'll do my best to answer. Thank you!
    Last edited by Stickyfan; 01-05-2012 at 01:21 AM.

  • #2
    Supreme Overlord Spookster's Avatar
    Join Date
    May 2002
    Location
    Marion, IA USA
    Posts
    6,280
    Thanks
    4
    Thanked 83 Times in 82 Posts
    I would imagine then you want to wrap the second image in an else statement otherwise it will print both of them if they are not a dealer.

    PHP Code:
    if($dealer['user_id'] > 0){
    // dealer image code
    }
    else {
    // default image code

    And FYI that is not a very readable way to check if the user is a dealer. Using a variable named $dealer to check for user ids where the user might be a dealer or a non-dealer is just misleading.
    Spookster
    CodingForums Supreme Overlord
    All Hail Spookster

  • Users who have thanked Spookster for this post:

    Stickyfan (01-05-2012)

  • #3
    New to the CF scene
    Join Date
    Nov 2011
    Posts
    6
    Thanks
    2
    Thanked 0 Times in 0 Posts
    Thank you. That sounds right.

    I'm trying to add the else statement, but am having issues working around the "print '" statement. How should I wrap the else statement around it?

  • #4
    Supreme Overlord Spookster's Avatar
    Join Date
    May 2002
    Location
    Marion, IA USA
    Posts
    6,280
    Thanks
    4
    Thanked 83 Times in 82 Posts
    PHP Code:
     
    if($dealer['user_id'] > 0){
        print 
    '
    <h3>How It Works</h3>
    <p>Click on each step to learn more</p>
    <p style="text-align:center;"><img alt="" border="0" src="'
    .D.'uploads/users/images/why-pre-sell-dealer.gif" style="width:465px; height:306px;" usemap="#whatspresell" />
      <map id="whatspresell" name="whatspresell">
        <area alt="" class="colorbox {iframe:true,height:300,width:300}" coords="156,1,300,49" href="'
    .D.'files/why-pre-sell-popup.php?id=94" shape="rect" />
        <area alt="" class="colorbox {iframe:true,height:625,width:810}" coords="327,77,463,131" href="'
    .D.'files/why-pre-sell-popup.php?id=95" shape="rect" />
        <area alt="" class="colorbox {iframe:true,height:650,width:800}" coords="295,182,440,237" href="'
    .D.'files/why-pre-sell-popup.php?id=96" shape="rect" />
        <area alt="" class="colorbox {iframe:true,height:700,width:900}" coords="156,258,303,302" href="'
    .D.'files/why-pre-sell-popup.php?id=97" shape="rect" />
        <area alt="" class="colorbox {iframe:true,height:400,width:900}" coords="13,179,159,232" href="'
    .D.'files/why-pre-sell-popup.php?id=98" shape="rect" />
        <area alt="" class="colorbox {iframe:true,height:450,width:550}" coords="1,62,134,119" href="'
    .D.'files/why-pre-sell-popup.php?id=106" shape="rect" />
      </map>
    </p>
    '
    ;
    }
    else {
    print 
    '

    <h3>How It Works</h3>
    <p>Click on each step to learn more</p>
    <p style="text-align:center;"><img alt="" border="0" src="'
    .D.'uploads/users/images/why-pre-sell-2.gif" style="width:465px; height:306px;" usemap="#whatspresell" />
      <map id="whatspresell" name="whatspresell">
        <area alt="" class="colorbox {iframe:true,height:300,width:300}" coords="156,1,300,49" href="'
    .D.'files/why-pre-sell-popup.php?id=94" shape="rect" />
        <area alt="" class="colorbox {iframe:true,height:625,width:810}" coords="327,77,463,131" href="'
    .D.'files/why-pre-sell-popup.php?id=95" shape="rect" />
        <area alt="" class="colorbox {iframe:true,height:650,width:800}" coords="295,182,440,237" href="'
    .D.'files/why-pre-sell-popup.php?id=96" shape="rect" />
        <area alt="" class="colorbox {iframe:true,height:700,width:900}" coords="156,258,303,302" href="'
    .D.'files/why-pre-sell-popup.php?id=97" shape="rect" />
        <area alt="" class="colorbox {iframe:true,height:400,width:900}" coords="13,179,159,232" href="'
    .D.'files/why-pre-sell-popup.php?id=98" shape="rect" />
        <area alt="" class="colorbox {iframe:true,height:450,width:550}" coords="1,62,134,119" href="'
    .D.'files/why-pre-sell-popup.php?id=99" shape="rect" />
      </map>
    </p>
    '
    ;

    Spookster
    CodingForums Supreme Overlord
    All Hail Spookster

  • #5
    New to the CF scene
    Join Date
    Nov 2011
    Posts
    6
    Thanks
    2
    Thanked 0 Times in 0 Posts
    Perfect! I was putting the beginning of the else statement below the "print" statement. Thanks very much for your help.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •