Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7526237
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T03:46:42+00:00 2026-05-30T03:46:42+00:00

public function genMenu($parent_id, $menu_type, $utype, $parent_token=0, $currentpage = 0) { $stmt = $this->db->prepare(SELECT n.page_id,

  • 0
public function genMenu($parent_id, $menu_type, $utype, $parent_token=0, $currentpage = 0) {
    $stmt = $this->db->prepare("SELECT n.page_id, p.short_name, p.token FROM navigation AS n, pages AS p, user_page_restr AS r WHERE n.parent_id = ? AND r.pg_id=p.id AND n.menu=? AND (r.user_type=? OR r.user_type=0)  AND n.page_id=p.id ORDER BY r.order") or die($this->db->error);
    $stmt->bind_param("iii", $parent_id, $menu_type, $utype) or die($stmt->error);
    $stmt->execute() or die($stmt->error);
    $stmt->store_result();
    $menu = array();
    $stmt->bind_result($menu['id'], $menu['short_name'], $menu['token']) or die($stmt->error);
    if ($stmt->num_rows > 0)
        echo "\n<ul>\n";
    while ($stmt->fetch()) {
        echo "<li ";
        if ($menu['token']==$currentpage) {
            echo 'class="active"';
        }
        echo ">";
        switch ($menu_type) {
            case 2:
                echo '<a href="?page=' . $parent_token;
                echo '&subpage=' . $menu['token'];
                echo '">' . $menu['short_name'] . '</a>';
                break;
            default:
                echo '<a href="?page=' . $menu['token'] . '">' . $menu['short_name'] . '</a>';
                break;
        }
        echo "</li>\n\n";
    }
    if ($stmt->num_rows > 0) 
        echo "</ul>\n";

    $stmt->close();
}

enter image description here

Take a look at this

        if ($menu['token']==$currentpage) {
            echo 'class="active"';
        }

Even if $menu[‘token’] is string and has exact value and $currentpage is 0, if condition returns result true and executes expression inside if (echo 'class="active"';)

Can anyone explain why this occurs?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-30T03:46:43+00:00Added an answer on May 30, 2026 at 3:46 am

    You have a casting issue. When you compare an integer to a string with the == operator the string is cast to its integer equivalent, which for a string that does not begin with a digit is 0.

    The answer depends on what you want to do. If you only want to match a string with a string use the === operator.

    If you want an empty string to match 0, you can use

    if ((string)$currentpage === $menu['token'])
    

    to make sure that the comparison is done string to string rather than the default int to int.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

public function receiveDomainNames($keyword) { try { $stmt = $this->_dbh->prepare(SELECT d.someField FROM domain d WHERE
I have this query: public function checkUser($phone) { $sql = SELECT name FROM users
public function dcr() { $query = $this->db->query(SELECT * FROM church_repo); foreach ($query->result() as $row)
this is my query: public function getDetails($userid, $orderby, $sort){ $query = $this->_em->createQueryBuilder() ->select('u') ->from('\Entities\Users',
public function gl_popular(){ $query=$this->db->query(SELECT DISTINCT new_ques_id FROM gl_mark_ques); //echo SELECT DISTINCT new_ques_id FROM gl_mark_ques
public function doesUserExist($u) { $this->dbConnect(); mysql_select_db($this->database); $sUser = mysql_real_escape_string($u); $query = SELECT username FROM
public function init(){ $this->view->user = Zend_Auth::getInstance()->getIdentity(); $this->view->siteName = Zend_Registry::get('config')->site->name; $this->view->menu = $this->_helper->generateMenu(Zend_Auth::getInstance()->getIdentity()); $this->view->slogan =
public function configure() { $this->widgetSchema['start_date'] = new sfWidgetFormInput(); $this->widgetSchema['end_date'] = new sfWidgetFormInput(); $this->validatorSchema->setPostValidator( new
Here's my RegisterController: public function saveforminformationAction(){ $request = $this->getRequest(); if($request->isPost()){ //I NEED HELP WITH
public function admin_view($user_id = NULL) { debug($this->User); exit; } public function view($user_id = null)

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.