Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Page 1 of 2 12 LastLast
Results 1 to 15 of 16
  1. #1
    Senior Coder
    Join Date
    Jun 2008
    Location
    Cornwall
    Posts
    2,088
    Thanks
    296
    Thanked 12 Times in 12 Posts

    Unhappy why does these same pieces of code produce different results?

    Hi All

    I have these two pieces of code
    PHP Code:
        $booleansearch = array('sQuery'=> '-region 1 -console -bundle''oActiveRefineByGroup' => $oRefineBy'bAdult' => true'iLimit'=>3'sColumnToReturn' => $returnedcolumns'sSort'=>'popularity''sMode' => 'boolean'); 
    and

    PHP Code:
    $booleansearch = array('sQuery'=> '$keywords''oActiveRefineByGroup' => $oRefineBy'bAdult' => true'iLimit'=>3'sColumnToReturn' => $returnedcolumns'sSort'=>'popularity''sMode' => 'boolean'); 
    but both produce different results, but the value of $keywords is exactly the same as in the first example.

    here is where i define $keywords
    PHP Code:
            switch($category)
            {
                case 
    "DVD";
                    
    $aw_id "240";
                    
    $aw_name "DVDs";
                    
    $keywords '-region 1 -console -bundle';
                    break;
                case 
    "CD";
                    
    $aw_id "241";
                    
    $aw_name "Music";
                    
    $keywords =  '-region 1 -console -bundle';
                    break;
                case 
    "Video Games";
                    
    $aw_id "579";
                    
    $aw_name "Video Games";
                    
    $keywords =  '-region 1 -console -bundle';
                    break;
                case 
    "Blu-Ray";
                    
    $aw_id "550";
                    
    $aw_name "Blu-Ray";
                    
    $keywords '-region 1 -console -bundle';
                    break;
                case 
    "Books";
                    
    $aw_id "538";
                    
    $aw_name "Books";
                    
    $keywords =  '-region 1 -console -bundle';
                    break;
            } 
    i need to use the varable in the query because the api service only allows upto four negative vales and im performing searches in a total of 30 different categories but i cant understand why the two produce different results

    is the $keywords being interpreted as something else? ive tried printing out the value and it is as expected.

    any help would be greatly appreciated
    cheers

  • #2
    God Emperor Fou-Lu's Avatar
    Join Date
    Sep 2002
    Location
    Saskatoon, Saskatchewan
    Posts
    16,980
    Thanks
    4
    Thanked 2,659 Times in 2,628 Posts
    They are not the same:
    PHP Code:
    $booleansearch = array('sQuery'=> '$keywords''oActiveRefineByGroup' => $oRefineBy'bAdult' => true'iLimit'=>3'sColumnToReturn' => $returnedcolumns'sSort'=>'popularity''sMode' => 'boolean');  

    // This should be:
    $booleansearch = array('sQuery'=> $keywords'oActiveRefineByGroup' => $oRefineBy'bAdult' => true'iLimit'=>3'sColumnToReturn' => $returnedcolumns'sSort'=>'popularity''sMode' => 'boolean'); 
    $keywords is wrapped in single quotations, so it is treating it as an unparsable string.
    PHP Code:
    header('HTTP/1.1 420 Enhance Your Calm'); 

  • #3
    Senior Coder
    Join Date
    Jun 2008
    Location
    Cornwall
    Posts
    2,088
    Thanks
    296
    Thanked 12 Times in 12 Posts
    hi mate, if i remove the 's it still produces the same results as with 's but different to that if i type in the value of $keywords instead of $keyword.

    it is very odd

    thanks for your reply

  • #4
    God Emperor Fou-Lu's Avatar
    Join Date
    Sep 2002
    Location
    Saskatoon, Saskatchewan
    Posts
    16,980
    Thanks
    4
    Thanked 2,659 Times in 2,628 Posts
    I'm assuming that category has been determine? You don't have a default case there, so if there is no valid category you won't get a valid $keywords.

    In any case, if the value of $keywords is what you're expecting, than the results should be the same. Ensure you're not running against a cached page.
    PHP Code:
    header('HTTP/1.1 420 Enhance Your Calm'); 

  • #5
    Senior Coder
    Join Date
    Jun 2008
    Location
    Cornwall
    Posts
    2,088
    Thanks
    296
    Thanked 12 Times in 12 Posts
    hi mate,

    yeah category is defined
    PHP Code:
            $category_list = array('DVD' => 'The latest blockbuster DVDs.',
            
    'CD' => 'Chart hit CDs from the hottest artists.',
            
    'Video Games' => 'Multi platform video games',
            
    'Blu-Ray' => 'Picture perfect Blu-Ray DVDs.',
            
    'Books' => 'From bestselling authors'); 
    here
    PHP Code:
        foreach ($category_list as $category => $sub_category
        { 
    how does one 'Ensure you're not running against a cached page'?

    thanks
    Luke

  • #6
    Senior Coder
    Join Date
    Jun 2008
    Location
    Cornwall
    Posts
    2,088
    Thanks
    296
    Thanked 12 Times in 12 Posts
    something even stranger i have changed all the $keywords to $keywordz and it now seems to match the expected results??? and i've checked my code and cant see where i may of defined $keywords already!

    but at least its now working

    thanks
    Luke

  • #7
    God Emperor Fou-Lu's Avatar
    Join Date
    Sep 2002
    Location
    Saskatoon, Saskatchewan
    Posts
    16,980
    Thanks
    4
    Thanked 2,659 Times in 2,628 Posts
    Quote Originally Posted by LJackson View Post
    something even stranger i have changed all the $keywords to $keywordz and it now seems to match the expected results??? and i've checked my code and cant see where i may of defined $keywords already!

    but at least its now working

    thanks
    Luke
    o.O
    Serously? That is weird. It wouldn't matter if it was previously defined and just reused as long as its not changed between you're switch and you're later implementation of it.
    Now just do a search and replace all for $keywordz to $keywords to see if it still behaves.

    The easiest way to ensure you're not cached is to just add a query string. I assume you're on localhost for testing, so rather than play around with a pile of settings, just use http://127.0.0.1/path/to/file.php?t=4adfj449339
    where t is anything you want. As soon as the querystring has changed to one that is not cached, it will serve out a new page.
    PHP Code:
    header('HTTP/1.1 420 Enhance Your Calm'); 

  • #8
    Senior Coder
    Join Date
    Jun 2008
    Location
    Cornwall
    Posts
    2,088
    Thanks
    296
    Thanked 12 Times in 12 Posts
    tried the replace all and lowembyhold the wrong results again

    this is my entire code
    PHP Code:
        <?php
        
    if($_SESSION['page'] == "entertainment")
        {
            
    $category_list = array('DVD' => 'The latest blockbuster DVDs.',
            
    'CD' => 'Chart hit CDs from the hottest artists.',
            
    'Video Games' => 'Multi platform video games',
            
    'Blu-Ray' => 'Picture perfect Blu-Ray DVDs.',
            
    'Books' => 'From bestselling authors');
         }
    ?>

        <div id="category_left">
        <div class="links_container">
        <?php
        
    foreach ($category_list as $category => $sub_category
        {
    ?>
            <div class="individual_link_container">
            
            <h2 class="red">
            <?php echo $category?>
            </h2>
            
            <div class="small">
            <?php echo $sub_category;?>
            </div>
            
            </div>
            <?php
            $x
    ++;
        }
    ?>
        </div>
        </div>

        
        <div id="category_right">
        <?php
        
    foreach ($category_list as $category => $sub_category
        {
            switch(
    $category)
            {
                case 
    "DVD";
                    
    $aw_id "240";
                    
    $aw_name "DVDs";
                    
    $keywords "-region 1";
                    break;
                case 
    "CD";
                    
    $aw_id "241";
                    
    $aw_name "Music";
                    
    $keywords "cd -christmas";
                    break;
                case 
    "Video Games";
                    
    $aw_id "579";
                    
    $aw_name "Video Games";
                    
    $keywords "video games -console";
                    break;
                case 
    "Blu-Ray";
                    
    $aw_id "550";
                    
    $aw_name "Blu-Ray";
                    
    $keywords "-region 1";
                    break;
                case 
    "Books";
                    
    $aw_id "538";
                    
    $aw_name "Books";
                    
    $keywords "novel -Cannabis -logbook -Wetshoes";
                    break;
            }
            
            print 
    "<div class='category_container'>";
            print 
    "<h2 class='category_header red'>$category</h2>";
            
            
    #GET TOP 5 ITEMS FOR EACH CATEGORY
            
    $AW_catid $aw_id;
            
    $AW_cat $aw_name;
            
    $keywords "";
            
    $oRefineBy = new stdClass();
            
    $oRefineBy -> iId 4;
            
    $oRefineBy -> sName 'Category';
            
    $oRefineByDefinition = new stdClass();
            
    $oRefineByDefinition -> sId $AW_catid;
            
    $oRefineByDefinition -> sName $AW_cat;
            
    $oRefineBy -> oRefineByDefinition $oRefineByDefinition;
            
    $returnedcolumns = array(iCategoryIdiMerchantIdsAwImageUrlfStorePricesAwThumbUrlsName,sAwImageUrl,sMerchantImageUrl,sMerchantThumbUrl,sDescription,sBrand);        
            
    $booleansearch = array('sQuery'=> $keywords'oActiveRefineByGroup' => $oRefineBy'bAdult' => true'iLimit'=>3'sColumnToReturn' => $returnedcolumns'sSort'=>'popularity''sMode' => 'boolean');
            
    $oResponse$oClient->call('getProductList'$booleansearch);     
                foreach(
    $oResponse->oProduct as $oProduct)
                {
                    
    $img htmlspecialchars($oProduct->sMerchantImageUrl);
                    
    $img2 htmlspecialchars($oProduct->sAwThumbUrl);
                    
    $price $oProduct->fPrice;
                    
    $store $oProduct->iMerchantId;
                    
    $catid $oProduct->iCategoryId;
                    
    $desc $oProduct->sDescription;?>
                    <div class="individual_top5">
                    <h3 class="individual_top5_headers"><?php print $oProduct->sName;?></h3>
                    <div class="individual_top5_images">
                    <?php
                    
    print "<img src='$img2' height='85px' alt='$desc' title='$desc' /></div>";
                    print 
    $price." ".$store." ".$catid;?>
                    </div>
                    <?php
                
    }
                
            print 
    "</div>";
        }
            
        
    ?>
        </div>
        <?php footer();?>
    thanks for the catched info btw

  • #9
    God Emperor Fou-Lu's Avatar
    Join Date
    Sep 2002
    Location
    Saskatoon, Saskatchewan
    Posts
    16,980
    Thanks
    4
    Thanked 2,659 Times in 2,628 Posts
    o.O
    You did make an error:
    PHP Code:
            $keywords ""// <-- you dumped the $keywords here :P
            
    $oRefineBy = new stdClass();
            
    $oRefineBy -> iId 4;
            
    $oRefineBy -> sName 'Category';
            
    $oRefineByDefinition = new stdClass();
            
    $oRefineByDefinition -> sId $AW_catid;
            
    $oRefineByDefinition -> sName $AW_cat;
            
    $oRefineBy -> oRefineByDefinition $oRefineByDefinition;
            
    $returnedcolumns = array(iCategoryIdiMerchantIdsAwImageUrlfStorePricesAwThumbUrlsName,sAwImageUrl,sMerchantImageUrl,sMerchantThumbUrl,sDescription,sBrand);        
            
    $booleansearch = array('sQuery'=> $keywords'oActiveRefineByGroup' => $oRefineBy'bAdult' => true'iLimit'=>3'sColumnToReturn' => $returnedcolumns'sSort'=>'popularity''sMode' => 'boolean'); 
    Also, you probably should change you're $returnedcolumns to strings. I assume they are to be strings?

    I'd actually keep the $keywords initializer, but move it above you're switch. This way if for whatever reason there is no base case match, you still have $keywords available, but its no longer a non-existant variable.
    PHP Code:
    header('HTTP/1.1 420 Enhance Your Calm'); 

  • Users who have thanked Fou-Lu for this post:

    LJackson (01-22-2010)

  • #10
    Senior Coder
    Join Date
    Jun 2008
    Location
    Cornwall
    Posts
    2,088
    Thanks
    296
    Thanked 12 Times in 12 Posts
    crikey.. cant believe i missed that

    thanks for spotting it at least we now know what was causing the cockup

    i have another little problem array based i think

    i have pulled out all the product data as i want including the price and the store id but i am trying to perform another call to the api to get the store name out which relates to the id. but i keep getting the same name out everytime, its a long shot but could you look at my syntax to see if there are any obvious mistakes in there for me please.

    here is my full code
    PHP Code:
            #GET TOP 5 ITEMS FOR EACH CATEGORY
            $AW_catid = $aw_id;
            $AW_cat = $aw_name;
            $oRefineBy = new stdClass();
            $oRefineBy -> iId = 4;
            $oRefineBy -> sName = 'Category';
            $oRefineByDefinition = new stdClass();
            $oRefineByDefinition -> sId = $AW_catid;
            $oRefineByDefinition -> sName = $AW_cat;
            $oRefineBy -> oRefineByDefinition = $oRefineByDefinition;
            $returnedcolumns = array(iCategoryId, iMerchantId, sAwImageUrl, fStorePrice, sAwThumbUrl, sName,sAwImageUrl,sMerchantImageUrl,sMerchantThumbUrl,sDescription,sBrand);        
            $booleansearch = array('sQuery'=> $keywords, 'oActiveRefineByGroup' => $oRefineBy, 'bAdult' => true, 'iLimit'=>3, 'sColumnToReturn' => $returnedcolumns, 'sSort'=>'popularity', 'sMode' => 'boolean');
            $oResponse= $oClient->call('getProductList', $booleansearch);     
                foreach($oResponse->oProduct as $oProduct)
                {
                    $img = htmlspecialchars($oProduct->sMerchantImageUrl);
                    $img2 = htmlspecialchars($oProduct->sAwThumbUrl);
                    $price = $oProduct->fPrice;
                    $store = $oProduct->iMerchantId;
                    $catid = $oProduct->iCategoryId;
                    $desc = $oProduct->sDescription;
                    $merchantid = $oProduct->iMerchantId;//the id i am trying to get the store name for
                    print $merchantid;
                    
                    #GET MERCHANT NAME
                    $merchantcolumns = array(iId,sName,sStrapline,sDescription,sLogoUrl,sDisplayUrl,sClickThroughUrl,oDiscountCode);
                    $merchantrows = array("iId" => $merchantid, "sColumnToReturn" => $merchantcolumns, "iAdult" => 1);
                    $oResponse= $oClient->call('getMerchant', $merchantrows);
                    print $oResponse->oMerchant->sName;
                    foreach($oResponse->oMerchant as $details)
                    {    
                        $merchName =$details->sName;//the store name    
                    }

                    ?>
                    <div class="individual_top5">
                    <h3 class="individual_top5_headers"><?php print $oProduct->sName;?></h3>
                    <div class="individual_top5_images">
                    
                    <img src='<?php echo $img2;?>' height='85px' alt='<?php echo $desc;?>' title='<?php echo $desc;?>' /></div>
                    <div class='buyitnow_container'>
                    
                    <div class="buyitnow_store"><span class="bold red">Buy it now</span><br />from <?php echo $merchName/*echoing the store name*/." for &pound;".$price;?></div>
                    </div>
                    
                    <div class='compareit_container'>
                    <div class="compareit_link">OR <br />compare prices</div>
                    </div>
                    
                    </div>
                    <?php
                
    }
    cheers
    Luke

  • #11
    Senior Coder
    Join Date
    Jun 2008
    Location
    Cornwall
    Posts
    2,088
    Thanks
    296
    Thanked 12 Times in 12 Posts
    still unable to figure this out anyone know why i am unable to pull out the correct merchant name that matches the id???

    im puzzeled
    thanks

  • #12
    God Emperor Fou-Lu's Avatar
    Join Date
    Sep 2002
    Location
    Saskatoon, Saskatchewan
    Posts
    16,980
    Thanks
    4
    Thanked 2,659 Times in 2,628 Posts
    I can't test anything that you're doing, I'm not even certain what you're $oClient is. I presume a webservice handle of some sort.
    Anyway, the first thing I'd do is change this:
    PHP Code:
                    #GET MERCHANT NAME
                    
    $merchantcolumns = array(iId,sName,sStrapline,sDescription,sLogoUrl,sDisplayUrl,sClickThroughUrl,oDiscountCode);
                    
    $merchantrows = array("iId" => $merchantid"sColumnToReturn" => $merchantcolumns"iAdult" => 1);
                    
    $oResponse$oClient->call('getMerchant'$merchantrows);
                    print 
    $oResponse->oMerchant->sName;
                    foreach(
    $oResponse->oMerchant as $details)
                    {    
                        
    $merchName =$details->sName;//the store name    
                    

    In particular, the $oResponse part. Since you're outer loop is also controlled by the $oResponse variable, changing it in the inside can lead to undesired results. Try that, see if that works.
    PHP Code:
    header('HTTP/1.1 420 Enhance Your Calm'); 

  • #13
    Senior Coder
    Join Date
    Jun 2008
    Location
    Cornwall
    Posts
    2,088
    Thanks
    296
    Thanked 12 Times in 12 Posts
    hi mate,

    the oClient i think is what you said it is or something similar, as i am making two different calls to the api 1 for product data and one for the relivant merchant data which relates to the product data.

    the oRespose is just a varible which states the call procedure so each call to the api requires an oRespose (or any other name you want to give it)

    thats why i thought using my loop setup the way it is it would get the merchantid e.g 245 and then have another call to the api in the same loop to get the merchant name that matches 245, but as per usual it doesnt wanna play

    sorry for being difficult and i relise that it is difficult for you to test things out or to understand what each bit does (not even i know/understand that fully lol) but at the moment your my best shot at solving this

    p.s i trieds changing the name of the second oResponse but no change, i know the original merchant values are correct its just getting the second call to use them as i intend, and im not sure if its an error at my end, which is very likley or if im doing the call incorrectly?

    cheers
    Luke
    Last edited by LJackson; 01-23-2010 at 01:18 AM.

  • #14
    Senior Coder
    Join Date
    Jun 2008
    Location
    Cornwall
    Posts
    2,088
    Thanks
    296
    Thanked 12 Times in 12 Posts
    ok if i

    print_r($oResponse);

    i get the list of all the merchants and their ids and names which is a good thing

    so you'd of thought a simple while statment would work to print out the name? but nope unless the code is wrong it is 1.30am uk time

    here is what ive done
    PHP Code:
                    #GET MERCHANT NAME
                    
    $merchantcolumns = array(iId,sName);
                    
    $merchantrows = array("sColumnToReturn" => $merchantcolumns"iAdult" => 1);
                    
    $oResponse$oClient->call('getMerchant'$merchantrows);
                    
    $storeid $oResponse->oMerchant->iId;
                    
    //print_r($oResponse);
                    
    while($storeid == $merchantid){
                    print 
    $oResponse->oMerchant->sName;
                    } 
    but nothing prints out again?

  • #15
    God Emperor Fou-Lu's Avatar
    Join Date
    Sep 2002
    Location
    Saskatoon, Saskatchewan
    Posts
    16,980
    Thanks
    4
    Thanked 2,659 Times in 2,628 Posts
    The while is incorrect, it will only continue while the store matches the merchant. There is no guarantee that it will be the first or the sequential in the list.
    Assuming that it follows the above, you should be able to loop the $oResponse->oMerchant for each merchants, and pull out and compare the $merchantid to $storeid.
    PHP Code:
    header('HTTP/1.1 420 Enhance Your Calm'); 


  •  
    Page 1 of 2 12 LastLast

    Posting Permissions

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