...

View Full Version : strpos not working correctly



ninnypants
03-24-2009, 02:34 AM
so I'm using strpos inside an if statement to determine whether it should print out a sub list in a zen cart theme I'm modifying



strpos($var_linksList[$i]['link'], $has_sub[$sub])

which is equivilent to these


strpos('http://www.zonetreadmills.com/index.php?main_page=page&id=1&chapter=10','chapter=10');//working 68

strpos('http://www.zonetreadmills.com/index.php?main_page=products_all&disp_order=4','main_page=products_all');//not working


this is the context which they are used in


for($sub = 0; $sub < count($has_sub); $sub++){

if(strpos($var_linksList[$i]['link'], $has_sub[$sub])){
echo $sub_cats[$sub];
}

}

steelaz
03-24-2009, 03:21 AM
$pos = strpos('http://www.zonetreadmills.com/index.php?main_page=products_all&disp_order=4','main_page=products_all');

echo $pos; //prints 40


Works for me

ninnypants
03-24-2009, 03:27 AM
Yeah it works but for some reason it doesn't work on http://www.zonetreadmills.com/. The Products link in the top should have a suckerfish dropdown but does not. the support dropdown works but for some reason the products one does not. It was working before but the client made a change that change the url of the products page, and now it doesn't work anymore.

I've tried adding arbitrary sub lists to other items and it does not work on them either. It only works on the Support page.

steelaz
03-24-2009, 03:34 AM
Products link doesn't even have starting <ul>. Are you sure that part of code is being executed?

ninnypants
03-24-2009, 03:58 AM
Yeah it's being executed because the same piece of code that does the support dropdown does all of the others too.

Here's the full code
subcats.php


$has_sub = array();
$sub_cats = array();

/*
add the defineing variable to $has_sub
eg. customer service has a cPath of 5 so
$has_sub[0] = 'cPath=5';
*/
$has_sub[0] = 'main_page=products_all';
$has_sub[1] = 'id=1';


/*
add the markup for the sub categories list
to the exact same array numeral as it's parent
category's chapter.
eg. $has_sub[0] = 'chapter=10'; so
$sub_cats[0] = '<ul>
<li><a href="/service.php?p=shipping">Shipping</a></li>
<li><a href="/service.php?p=assembly">Assembly</a></li>
<li><a href="/service.php?p=guarantee">Guarantee</a></li>
<li><a href="/service.php?p=privacy">Privacy Policy</a></li>
<li><a href="/pdf/Frequently_Asked_Questions.pdf" target="_blank">F.A.Q.</a></li>
</ul>';
*/
$sub_cats[0] = '<ul>
<li><a href="http://www.zonetreadmills.com/index.php?main_page=products_all&disp_order=4">Treadmills</a>
<ul>
<li><a href="http://www.zonetreadmills.com/index.php?main_page=index&cPath=1_2">Folding</a></li>
<li><a href="http://www.zonetreadmills.com/index.php?main_page=index&cPath=1_3">Non-Folding</a></li>
</ul>
</li>
<li><a href="http://www.zonetreadmills.com/index.php?main_page=index&cPath=4">Ellipticals</a></li>
</ul>';

$sub_cats[1] = '<ul>
<li><a href="http://www.zonetreadmills.com/index.php?main_page=page&id=2&chapter=20">Customer Service</a>
<ul>
<li><a href="http://www.zonetreadmills.com/index.php?main_page=shippinginfo">Shipping</a></li>
<li><a href="http://www.zonetreadmills.com/index.php?main_page=page&id=4&chapter=40">Assembly</a></li>
<li><a href="http://www.zonetreadmills.com/index.php?main_page=page&id=5&chapter=50">Guarantee</a></li>
<li><a href="http://www.zonetreadmills.com/index.php?main_page=privacy">Privacy Policy</a></li>
<li><a href="http://www.zonetreadmills.com/index.php?main_page=page&id=6&chapter=60">FAQ</a></li>
</ul>
</li>
<li><a href="http://www.zonetreadmills.com/index.php?main_page=page&id=7&chapter=70">Technical Support</a>
<ul>
<li><a href="http://www.zonetreadmills.com/index.php?main_page=page&id=8&chapter=80">Warranty Registration</a></li>
<li><a href="http://www.zonetreadmills.com/index.php?main_page=page&id=9&chapter=90">Service &amp; Parts</a></li>
<li><a href="http://www.zonetreadmills.com/index.php?main_page=page&id=10&chapter=100">Product Manuals</a></li>
<li><a href="http://www.zonetreadmills.com/index.php?main_page=page&id=11&chapter=110">Technical Self Help</a></li>
<li><a href="http://www.zonetreadmills.com/index.php?main_page=page&id=12&chapter=120">Specifications</a></li>
</ul>
</li>
</ul>';

tpl_ezpages_bar_header.php


<?php
/**
* Page Template
*
* Displays EZ-Pages Header-Bar content.<br />
*
* @package templateSystem
* @copyright Copyright 2003-2006 Zen Cart Development Team
* @copyright Portions Copyright 2003 osCommerce
* @license http://www.zen-cart.com/license/2_0.txt GNU Public License V2.0
* @version $Id: tpl_ezpages_bar_header.php 3377 2006-04-05 04:43:11Z ajeh $
*/

/**
* require code to show EZ-Pages list
*/
include(DIR_WS_MODULES . zen_get_module_directory('ezpages_bar_header.php'));

require_once('subcats.php');
?>
<?php if (sizeof($var_linksList) >= 1) { ?>
<div id="navEZPagesTop">
<ul>
<?php for ($i=1, $n=sizeof($var_linksList); $i<=$n; $i++) {

if ($i==1) {
$kk = ' class="li_un"';
} else {
$kk = '';
}

?>

<li<?php echo $kk; ?>><a href="<?php echo $var_linksList[$i]['link']; ?>"><?php echo $var_linksList[$i]['name']; ?></a>

<?php

for($jj = 0; $jj < count($has_sub); $jj++){

if(strpos($var_linksList[$i]['link'], $has_sub[$jj])){
echo $sub_cats[$jj];
}

}

?>
</li>
<?php echo ($i < $n ? EZPAGES_SEPARATOR_HEADER : '') . "\n"; ?>

<?php } // end FOR loop ?>

<div class="clear"></div>
</ul>
</div>
<?php } ?>

steelaz
03-24-2009, 04:07 AM
In tpl_ezpages_bar_header.php before "<?php if (sizeof($var_linksList) >= 1) { ?> " Add this line:


<pre><? var_dump($var_linksList); ?></pre>

And copy/paste results here.

ninnypants
03-24-2009, 04:33 AM
Here's the var dump

array(6) {
[1]=>
array(4) {
["id"]=>
string(2) "13"
["name"]=>
string(4) "Home"
["altURL"]=>
string(39) "http://www.zonetreadmills.com/index.php"
["link"]=>
string(39) "http://www.zonetreadmills.com/index.php"
}
[2]=>
array(4) {
["id"]=>
string(2) "14"
["name"]=>
string(8) "Products"
["altURL"]=>
string(79) "http://www.zonetreadmills.com/index.php?main_page=products_all&disp_order=4"
["link"]=>
string(79) "http://www.zonetreadmills.com/index.php?main_page=products_all&disp_order=4"
}
[3]=>
array(4) {
["id"]=>
string(1) "1"
["name"]=>
string(7) "Support"
["altURL"]=>
string(0) ""
["link"]=>
string(78) "http://www.zonetreadmills.com/index.php?main_page=page&id=1&chapter=10"
}
[4]=>
array(4) {
["id"]=>
string(2) "15"
["name"]=>
string(11) "Accessories"
["altURL"]=>
string(0) ""
["link"]=>
string(64) "http://www.zonetreadmills.com/index.php?main_page=page&id=15"
}
[5]=>
array(4) {
["id"]=>
string(2) "16"
["name"]=>
string(21) "About Zone Treadmills"
["altURL"]=>
string(0) ""
["link"]=>
string(64) "http://www.zonetreadmills.com/index.php?main_page=page&id=16"
}
[6]=>
array(4) {
["id"]=>
string(2) "17"
["name"]=>
string(10) "Contact Us"
["altURL"]=>
string(60) "http://www.zonetreadmills.com/index.php?main_page=contact_us"
["link"]=>
string(60) "http://www.zonetreadmills.com/index.php?main_page=contact_us"
}
}

steelaz
03-24-2009, 05:18 AM
Strange, that should be working. Try adding


<? error_reporting(E_ALL); ?>

at the very top of tpl_ezpages_bar_header.php, perhaps something else is triggering error.

ninnypants
03-24-2009, 05:59 AM
there are no errors before it, but that's to be expected because the support link's dropdown works and it comes after the products link. This really makes no sense.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum