-1

I have the statement if(isset($votes)) in votes_allvotes.tpl.php.

If I check the value on the same line right before that statement it tells me the value is 2, but for some reason the if statement refuses to acknowledge this.

Also tried if($votes > 0), did not work. I use this on 2 pages and on the other one it works fine, though there is nothing on this page that should conflict in any way with this (deleted everything on the page and it still didnt work.

Using Joomla 1.5.21 and Virtuemart 1.1.6

Here is the code:

<div class="rating" style="margin: 0px 0px 15px -9px">  
<?php
    $product_flypage = $_SERVER['REQUEST_URI'];
    echo ps_reviews::allvotes( $product_flypage );
?>

ps_reviews::allvotes:

    function allvotes( $product_id ) {
    if (strstr($product_id, '&')) {
        $arr = explode('&amp;', $product_id);

        $pro_arr = explode('=', $arr[2]);
        $cat_arr = explode('=', $arr[3]);

        $product_id = $pro_arr[1];
        $category_id = $cat_arr[1];
    }
    global $db;
    $tpl = new $GLOBALS['VM_THEMECLASS']();
    $dbc = new ps_DB;
    $q = "SELECT votes, rating FROM #__{vm}_product_votes "
        . "WHERE product_id='$product_id' ";
    $dbc->query( $q );

    $votes = $dbc->f("votes");
    $rating = $dbc->f("rating");

    if( $votes != 0)
        $tpl->set('votes', $votes );
    $tpl->set('rating', $rating );
    $tpl->set('product_id', $product_id );
    $tpl->set('category_id', $category_id );
    return $tpl->fetch( 'common/votes_allvotes.tpl.php' );
}

votes_allvotes.tpl.php (WHERE THE ACTUAL PROBLEM IS):

    if (isset($votes)) { ?>
<img src="<?php echo VM_THEMEURL ?>images/stars/<?php echo $rating ?>.gif" align="middle" border="0" alt="<?php echo $rating ?> stars" />&nbsp;
<?php echo $VM_LANG->_('PHPSHOP_TOTAL_VOTES').": ". $votes;
}
else { 
  if (!empty($my->id)) {
    if( $_GET['flypage']){
        echo "<li class='reviews'><a href='javascript:void(0)' style='color:#000;'><b>Wees de eerste om een recensie te schrijven!</b></a></li>";
    }else{
    echo "<a href='/index.php?page=shop.product_details&flypage=flypage.tpl&product_id=". $product_id ."&category_id=". $category_id ."&option=com_virtuemart&Itemid=1&lang=nl&review=yes'><b>Wees de eerste om een recensie te schrijven!</b></a>";
    }
  }else {
    echo $VM_LANG->_('PHPSHOP_REVIEW_LOGIN'); // Login to write a review!
  }
}
Akano
  • 41
  • 1
  • 6
  • 6
    Could you please clarify where are you having the problem, cuz I find it a bit difficult to see the point ot your question – DaGhostman Dimitrov Jul 23 '13 at 11:40
  • What does $tpl->fetch actually do? – Anigel Jul 23 '13 at 11:43
  • Methinks, you need to read up on `variable scope` and, if (and only if) it can't be helped the `global` construct. The only way your question/code combination maes sense, is if you check an local variable ($votes) outside its scope (globally). – Eugen Rieck Jul 23 '13 at 11:45
  • its in the if statement in votes_allvotes. $tpl->fetch fetches votes_allvotes.tpl.php – Akano Jul 23 '13 at 11:54

1 Answers1

0

isset might not be returning what you expected.

$votes = 0;

if(isset($votes)){

    echo 'Ooer missus ...';

}

I am not sure but perhaps you want ...

if((int)$votes > 0){

    echo 'well you got at least one vote ...';

}

Anyhow, if a condition does not do as you expect, then

var_dump()

that variable onto the page or into a log file and inspect it.

Even better, inspect it PRIOR to writing your conditional test.

Cups
  • 6,901
  • 3
  • 26
  • 30
  • Okay, if I use die(var_dump($votes)) the value is string 2, if I use only var_dump($votes) the value is NULL, I have no idea whats happening anymore xD – Akano Jul 23 '13 at 13:57