We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 38506
    • 103 Posts
    Hello !

    I need you! I have to make a search engine according to some criterion (price(prize), surface and city) that the chosen person.

    Here is my code:
    $parametres = array(
    'element' => 'getResources',
    'elementClass' => 'modSnippet',
    'parents' => $modx->resource->get('id'),
    'depth' => 2,
    'limit' => 3,
    'pageVarKey' => 'page',
    'includeTVs' => 1,
    'includeContent' => 1,
    'includeTVList' => 'ma_tv,description_terrain,tarif,ref,logo_constructeur,adresse,tel,site_constructeur',
    'tpl' => 'article',
    'processTVs' => 1,
    
    'pageLastTpl' => '<li class="control"><a[[+title]] href="[[+href]]">Dernière page</a></li>',
    'pageFirstTpl' => '<li class="control"><a[[+title]] href="[[+href]]">Première page</a></li>',
    );
    
    
    if ($_GET['Lieu']!=="none"){
    
    $ville=$_GET['Lieu'];
    
    $choix2 = strtoupper($_GET['prix']).$_GET['sup'].$_GET['Lieu'];
    
    switch ($choix2) {
    
    case "A0$ville": 
    
    $parametres = array_merge($parametres, array(
    'tvFilters' => 'adresse_terrain==$ville',
    ));
    
    return $modx->runSnippet('getPage', $parametres);
    
    break;
    }
    }


    I want that the parameters are sorted out according to the city where the chosen person. The problem it is because I do not manage to translate the $ville because when I puts that, it does not work. On the other hand if I filled with a chaine of character it work!

    Can you help me ?

    Excuse me for my English !
    • I don't think you can use a variable in the "case" part of a switch statement. The whole point of a switch statement is that the variable is in the "switch" part, and compares it with a set of "case" conditions that are specific values.

      What, exactly, are you trying to do with that comparison? If the case is that $choix2 == A0<something>, then you'll need to break up the A0 + $ville string somewhere and just check for the A0.
        Studying MODX in the desert - http://sottwell.com
        Tips and Tricks from the MODX Forums and Slack Channels - http://modxcookbook.com
        Join the Slack Community - http://modx.org
      • After further research, it looks like you might be able to use something like this:
        switch ($choix2) {
         
        case $choix2 == "A0$ville": 
        ...
        


        This is because now the case part will evaluate to true or false.
          Studying MODX in the desert - http://sottwell.com
          Tips and Tricks from the MODX Forums and Slack Channels - http://modxcookbook.com
          Join the Slack Community - http://modx.org