Advanced Search

Page 1 of 2 12 LastLast
Results 1 to 10 of 12

Thread: display:none in PHP?

  1. #1
    Join Date
    Dec 2004
    Posts
    83
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Question display:none in PHP?

    I'm trying to figure out if there's anything that works like display:none but in PHP. It's module for Joomla.

    I'm using IF..ELSE statement and I want to be able to hide/disable the code for ELSE. It's a shopping cart, I'm trying to hide it when it's empty, and when something is in the basket then it shows up. This is the code for the shopping cart.

    PHP Code:
    <?php if( !defined'_VALID_MOS' ) && !defined'_JEXEC' ) ) die( 'Direct Access to '.basename(__FILE__).' is not allowed.' );

    if(!
    $vmMinicart) { ?>
    <hr>
    <?php ?>
    <div style="float: left;" >
    <?php echo $total_products ?>
    </div>
    <div style="float: right;">
    <?php echo $total_price ?>
    </div>
    <?php if (!$empty_cart && !$vmMinicart) { ?>
        <br/><br style="clear:both" /><div align="center">
        <?php echo $show_cart ?>
        </div><br/>

    <?php 
    echo 
    $saved_cart;
    ?>

    I would appreciate any help.

    v1ktor

  2. #2
    Join Date
    Jul 2007
    Location
    Azerbaijan, Baku
    Posts
    144
    Thanks
    11
    Thanked 27 Times in 25 Posts

    Default

    Code:
    <?php
    if($myshoppingcard != ""){
    ?>
    //your shopping card here
    
    <?php
    }
    else{
    ?>
    //If it is emtpy here
    <?php
    }
    ?>
    I don't know if it is correct way or not. But you can try it

  3. #3
    Join Date
    Jul 2006
    Location
    just north of Boston, MA
    Posts
    1,806
    Thanks
    13
    Thanked 72 Times in 72 Posts

    Default

    <?php if (!$empty_cart && !$vmMinicart) { ?>
    <br/><br style="clear:both" /><div align="center">
    <?php echo $show_cart ?>
    </div><br/>

    <?php }
    will only write out that html code if the shopping cart exists

  4. #4
    Join Date
    Mar 2006
    Location
    Illinois, USA
    Posts
    12,156
    Thanks
    262
    Thanked 690 Times in 678 Posts

    Default

    PHP is a way of writing html. Thus, decide what the html should be, and all you need to do after that is write the PHP to make that show up.

    The solutions above make sense to me, but if you want to use display none, that's possible too.

    <sometag style="<?php if (!condition) { echo 'display:none;'; } ?>">
    Daniel - Freelance Web Design | <?php?> | <html>| espa˝ol | Deutsch | italiano | portuguŕs | catalÓ | un peu de franšais | some knowledge of several other languages: I can sometimes help translate here on DD | Linguistics Forum

  5. #5
    Join Date
    Dec 2004
    Posts
    83
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    Thanks for quick replies.

    Here's what I did, but I'm getting an error code:

    PHP Code:
    <?php if( !defined'_VALID_MOS' ) && !defined'_JEXEC' ) ) die( 'Direct Access to '.basename(__FILE__).' is not allowed.' );

    <?
    php if (!$empty_cart && !$vmMinicart) { ?>
        <br/><br style="clear:both" /><div align="center">
        <?php echo $show_cart ?>
        </div><br/>

    <?php 

    else (!
    $vmMinicart) { ?>
    <hr>
    <?php ?>
    <div style="float: left;" >
    <?php echo $total_products ?>
    </div>
    <div style="float: right;">
    <?php echo $total_price ?>
    </div>

    <?php 
    echo 
    $saved_cart;
    ?>

    And the error is :

    Parse error: syntax error, unexpected '<' in .../default/templates/common/minicart.tpl.php on line 3

    Where did I mess up integrating piece of code?

    v1k

  6. #6
    Join Date
    Jan 2008
    Posts
    4,158
    Thanks
    28
    Thanked 623 Times in 619 Posts
    Blog Entries
    1

    Default

    This should work:
    PHP Code:
    <?php
    if( !defined'_VALID_MOS' ) && !defined'_JEXEC' ) ) die( 'Direct Access to '.basename(__FILE__).' is not allowed.' );

    if (!
    $empty_cart && !$vmMinicart) { ?>
        <br/><br style="clear:both" /><div align="center">
        <?php echo $show_cart ?>
        </div><br/>

    <?php 

    else (!
    $vmMinicart) { ?>
    <hr>
    <?php ?>
    <div style="float: left;" >
    <?php echo $total_products ?>
    </div>
    <div style="float: right;">
    <?php echo $total_price ?>
    </div>

    <?php 
    echo 
    $saved_cart;
    ?>
    Your problem was you had a <?php in the middle of a php code.
    Jeremy | jfein.net

  7. #7
    Join Date
    Dec 2004
    Posts
    83
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    Thanks Nile, but I still got error code:


    Parse error: syntax error, unexpected '{' in .../default/templates/common/minicart.tpl.php on line 11

  8. #8
    Join Date
    Jan 2008
    Posts
    4,158
    Thanks
    28
    Thanked 623 Times in 619 Posts
    Blog Entries
    1

    Default

    PHP Code:
    <?php
    if( !defined'_VALID_MOS' ) && !defined'_JEXEC' ) ) die( 'Direct Access to '.basename(__FILE__).' is not allowed.' );

    if (!
    $empty_cart && !$vmMinicart) { ?>
        <br/><br style="clear:both" /><div align="center">
        <?php echo $show_cart ?>
        </div><br/>

    <?php 
    }else
    if (!
    $vmMinicart) { ?>
    <hr>
    <?php ?>
    <div style="float: left;" >
    <?php echo $total_products ?>
    </div>
    <div style="float: right;">
    <?php echo $total_price ?>
    </div>

    <?php 
    echo 
    $saved_cart;
    ?>
    Jeremy | jfein.net

  9. #9
    Join Date
    Dec 2004
    Posts
    83
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    Ahhhhh another one...


    Parse error: syntax error, unexpected '}' in .../default/templates/common/minicart.tpl.php on line 21

  10. #10
    Join Date
    Jan 2008
    Posts
    4,158
    Thanks
    28
    Thanked 623 Times in 619 Posts
    Blog Entries
    1

    Default

    PHP Code:
    <?php
    if( !defined'_VALID_MOS' ) && !defined'_JEXEC' ) ) die( 'Direct Access to '.basename(__FILE__).' is not allowed.' );

    if (!
    $empty_cart && !$vmMinicart) { ?>
        <br/><br style="clear:both" /><div align="center">
        <?php echo $show_cart ?>
        </div><br/>

    <?php 
    }else
    if (!
    $vmMinicart) { ?>
    <hr>
    <?php ?>
    <div style="float: left;" >
    <?php echo $total_products ?>
    </div>
    <div style="float: right;">
    <?php echo $total_price ?>
    </div>

    <?php  
    echo $saved_cart;
    ?>
    This should work.
    Jeremy | jfein.net

Bookmarks

Posting Permissions

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