I need help with this php code.

Discussion in 'PHP' started by niravdave, Jan 25, 2010.

  1. #1
    I have been struggling with this code, can anyone here help me on finding whats going wrong inside? Sorry I am a newbie, so not well versed with php.

     
      <?php if($countryid == '42'){ 
         echo "<a style=\"cursor:pointer;cursor:hand;\" onclick=\"MM_showHideLayers('popuptop','','show')\"><h2><?php echo $rowcat['catname']; ?><?php if($show_cat_adcount) { ?><span class=\"count\">(<?php echo $adcount; ?>)</span><?php } ?> </h2></a>";
        } 
        else {    
        echo "<a href=\"<?php echo $catlink; ?>\"><h2><?php echo $rowcat['catname']; ?><?php if($show_cat_adcount) { ?><span class=\"count\">(<?php echo $adcount; ?>)</span><?php } ?> </h2> </a>";
        }
        
        ?>
    
    PHP:
     
    niravdave, Jan 25, 2010 IP
  2. Nei

    Nei Well-Known Member

    Messages:
    106
    Likes Received:
    3
    Best Answers:
    1
    Trophy Points:
    170
    #2
    You use the php code (<?php echo $rowcat['catname']; ?> for example) in the string. It isn't correct.
    Instead of
    echo "<h2><?php echo $rowcat['catname']; ?>";
    PHP:
    you should write something like
    echo "<h2>".$rowcat['catname'];
    PHP:
     
    Nei, Jan 25, 2010 IP
  3. ads2help

    ads2help Peon

    Messages:
    2,142
    Likes Received:
    67
    Best Answers:
    1
    Trophy Points:
    0
    #3
    As stated by Nei, your <?php was not closed yet but you open a new <?php again

    Another way to write the codes is:

    <?php if ($countryid == '42'){ ?>
      <a style="cursor:pointer;cursor:hand;" onclick="MM_showHideLayers('popuptop','','show')"><h2><?php echo $rowcat['catname']; ?><?php if($show_cat_adcount) { ?><span class="count">(<?php echo $adcount; ?>)</span><?php } ?> </h2></a>
    <?php } else { ?>  
      <a href="<?php echo $catlink; ?>"><h2><?php echo $rowcat['catname']; ?><?php if($show_cat_adcount) { ?><span class="count">(<?php echo $adcount; ?>)</span><?php } ?> </h2> </a>
    <?php } ?>
    PHP:
     
    ads2help, Jan 25, 2010 IP
  4. niravdave

    niravdave Active Member

    Messages:
    675
    Likes Received:
    14
    Best Answers:
    0
    Trophy Points:
    88
    #4
    @Nei & ads2help

    Thank you both! I am going to try this 2nite and will update!

    Cheers
    Dave
     
    niravdave, Jan 26, 2010 IP
  5. blacksheep666

    blacksheep666 Active Member

    Messages:
    68
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    93
    #5
    
    <?php 
    	if($countryid == '42')
    	{
         	echo "<a style='cursor:pointer;' onclick=\"MM_showHideLayers('popuptop','','show')\"><h2>".$rowcat['catname'];
    		if($show_cat_adcount) 
    		 	echo "<span class=\"count\">(".$adcount.")</span>";
    		echo "</h2></a>";
    	}
        else 
    	{    
        	echo "<a href='$catlink'><h2>".$rowcat['catname'];
    		if($show_cat_adcount) 
    			echo "<span class='count'>(".$adcount.")</span>";
    		echo "</h2> </a>";
        }   
    ?>
    
    
    PHP:
     
    blacksheep666, Jan 26, 2010 IP
  6. puppetguy

    puppetguy Peon

    Messages:
    85
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #6
    <?php 
    if($countryid == '42'){
    echo "<a style=\"cursor:pointer;cursor:hand;\" onclick=\"".MM_showHideLayers('popuptop','','show')."\"><h2>".$rowcat['catname'];
    if($show_cat_adcount) {
    echo "<span class=\"count\">(".$adcount.")</span></h2></a>";
    } 
    }else{    
    echo "<a href=\"".$catlink."\"><h2>";
    echo $rowcat['catname'];
    if($show_cat_adcount) {
    echo "<span class=\"count\">(".$adcount.")</span></h2> </a>";
    }
    }
    ?>
    PHP:
     
    puppetguy, Feb 3, 2010 IP